package com.szholly.pro.watergas_server.ps.android.controller;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.szholly.plug.safe.entity.role.RoleInitHelper;
import com.szholly.plug.safe.entity.user.UserEntity;
import org.apache.commons.lang3.ObjectUtils;
import org.codehaus.jackson.map.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.szholly.pro.watergas_server.common.data.DataUtil;
import com.szholly.pro.watergas_server.common.util.RedisHelper;
import com.szholly.pro.watergas_server.ps.service.DomainService;
import com.szholly.pro.watergas_server.ps.service.OperationDataVaildService;
import com.szholly.utils.session.SessionFactory;
import com.szholly.utils.session.provider.ISessionProvider;
import com.szholly.utils.spring.SpringBeanFactory;
import com.szholly.utils.util.JSONUtils;
import com.szholly.utils.util.StringUtils;
import com.szholly.data.common.util.ConvertCaptionUtils;
import com.szholly.data.common.util.JSONConvertUtils;
import com.szholly.data.general.GlobalParameter;
import com.szholly.data.general.ITable;
import com.szholly.data.general.ITableFactory;
import com.szholly.data.general.RowBase;
import com.szholly.data.general.interceptor.DbEditType;
import com.szholly.plug.form.core.interceptor.FormEditInterceptorClass;

import lrq.common.PropertiesUnit;
import net.sf.json.JSONArray;
import net.sf.json.JSONNull;
import net.sf.json.JSONObject;

@Controller
@RequestMapping("/android/water/*")
public class WaterAndroidController {
	private String token = "android_token";
	private String VersionNo = "1.0";
	private int signInRange = 1000;// 签到范围
	@Autowired
	OperationDataVaildService operationDataVaildService;

	/**
	 * android组长名称
	 * 
	 * @param userName
	 * @param password
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/getLeaderName")
	@ResponseBody
	public String getLeaderName(String group_id) {
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		if (group_id.isEmpty()) {
			return "";
		}
		String sql = "select t2.c_userealname,t1.user_id from OC_GROUP_ASSO t1 left join SAFE_USER t2 on" + " t1.user_id=t2.s_userid where t1.group_head='1' ";
		sql += " and t1.group_id=@group_id";
		parms.add(new GlobalParameter("group_id", group_id));
		List<RowBase> rows = DataUtil.getSelectRows(sql, parms);
		if (rows != null && rows.size() >= 0) {
			return JSONUtils.toJSONString(rows);
		} else {
			return "";
		}
	}

	/**
	 * 删除创建未完成的任务
	 * 
	 *
	 */
	@RequestMapping("/delUndoneGenerate")
	@ResponseBody
	public String delUndoneGenerate(String TASK_CODE) throws Exception {
		if (TASK_CODE.isEmpty()) {
			return "{\"result\":false}";
		}
		List<GlobalParameter> parms = new ArrayList();
		String Sql = "delete from OP_TASK t where t.TASK_STATUS = '0' and t.TASK_CODE = @TASK_CODE";
		parms.add(new GlobalParameter("TASK_CODE", TASK_CODE));
		int i = DataUtil.ExecuteUpdateSql(Sql, parms);
		if (i == 0) {
			return "{\"result\":true}";
		} else {
			return "{\"result\":false}";
		}
	}

	/**
	 * android获取站点信息
	 * 
	 * @param userName
	 * @param password
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/getStationId")
	@ResponseBody
	public String getStationId(String wwtp_id) {
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		if (wwtp_id == null && wwtp_id.equals("")) {
			return "";
		}
		String sql = "select t.EXP_NO as STATION_ID,t.FLOW_TYPE from BC_SITE_INFO t where wwtp_id ='" + wwtp_id + "'";
		List<RowBase> rows = DataUtil.getSelectRows(sql, parms);
		if (rows != null && rows.size() >= 0) {
			return JSONUtils.toJSONString(rows);
		} else {
			return "";
		}
	}

	/**
	 * android获取供水现场考核参数
	 * 
	 * @param userName
	 * @param password
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/getGsXCKHParam")
	@ResponseBody
	public String getGsXCKHParam(String stationCode) {
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		String sql = "SELECT t1.s_domaincaption,t1.s_domaincode from BC_SITE_POLL t " + "left join data_defulatdomain t1 on t.name = t1.S_DOMAINCODE  " + "where t1.S_DOMAINNAME like '%供水参数%' ";
		if (!stationCode.isEmpty()) {
			sql += " and t.SITE_ID=@stationCode";
			parms.add(new GlobalParameter("stationCode", stationCode));
		}
		List<RowBase> rows = DataUtil.getSelectRows(sql, parms);
		if (rows != null && rows.size() >= 0) {
			return JSONUtils.toJSONString(rows);
		} else {
			return "";
		}
	}

	/**
	 * android污水日常校准任务详情
	 * 
	 */
	@RequestMapping("/getRcjzDetail")
	@ResponseBody
	public String getRcjzDetail(String tableName, String taskCode, String stationId) {
		if (tableName.isEmpty() || taskCode.isEmpty() || stationId.isEmpty()) {
			return "[]";
		}
		tableName = tableName.toUpperCase();
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		String sql = "select t1.name as devicename,to_char(t.verify_date,'yyyy-MM-dd HH24:MI:SS') as myverify_date,t.* from OPERATION_DAILY_VERIFICATION t left join (select * from BC_SITE_DEVICE_RPT where monitor_point = '" + stationId + "') t1 on t1.device_num = t.device_num where task_code = '" + taskCode + "'";
		// parms.add(new GlobalParameter("tableName", tableName));
		// parms.add(new GlobalParameter("taskCode", taskCode));
		List<RowBase> rows = DataUtil.getSelectRows(sql, parms);
		if (rows != null && rows.size() >= 0) {
			return JSONUtils.toJSONString(rows);
		} else {
			return "[]";
		}

	}

	/**
	 * android污水超标比对任务详情
	 * 
	 */
	@RequestMapping("/getCbbdDetail")
	@ResponseBody
	public String getCbbdDetail(String tableName, String taskCode) {
		if (tableName.isEmpty() || taskCode.isEmpty()) {
			return "[]";
		}
		tableName = tableName.toUpperCase();
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		String sql = "select * from " + tableName + " where task_id = '" + taskCode + "'";
		// parms.add(new GlobalParameter("tableName", tableName));
		// parms.add(new GlobalParameter("taskCode", taskCode));
		List<RowBase> rows = DataUtil.getSelectRows(sql, parms);
		if (rows != null && rows.size() >= 0) {
			return JSONUtils.toJSONString(rows);
		} else {
			return "[]";
		}

	}

	/**
	 * android污水标样核查任务详情
	 * 
	 */
	@RequestMapping("/getByhcDetail")
	@ResponseBody
	public String getByhcDetail(String tableName, String taskCode, String stationId) {
		if (tableName.isEmpty() || taskCode.isEmpty() || stationId.isEmpty()) {
			return "[]";
		}
		tableName = tableName.toUpperCase();
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		String sql = "select t1.name,t2.s_domaincaption,t.* from OP_STAND_VERI t left join  monitor_equipment t1 on t1.monitor_pollutants = t.test_project  " + "left join DATA_DEFULATDOMAIN t2 on t2.s_domaincode = t.test_project " + "where t2.S_DOMAINNAME ='MONITOR_PARAM' and t1.monitor_point = '" + stationId + "' and t.task_code ='" + taskCode + "' ";
		// parms.add(new GlobalParameter("tableName", tableName));
		// parms.add(new GlobalParameter("taskCode", taskCode));
		List<RowBase> rows = DataUtil.getSelectRows(sql, parms);
		if (rows != null && rows.size() >= 0) {
			return JSONUtils.toJSONString(rows);
		} else {
			return "[]";
		}

	}

	/**
	 * android污水水样比对任务详情
	 * 
	 */
	@RequestMapping("/getSybdDetail")
	@ResponseBody
	public String getSybdDetail(String tableName, String taskCode) {
		if (tableName.isEmpty() || taskCode.isEmpty()) {
			return "[]";
		}
		tableName = tableName.toUpperCase();
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		String sql = "select t.* from " + tableName + " t  where t.task_id = '" + taskCode + "'";
		// parms.add(new GlobalParameter("tableName", tableName));
		// parms.add(new GlobalParameter("taskCode", taskCode));
		List<RowBase> rows = DataUtil.getSelectRows(sql, parms);
		if (rows != null && rows.size() >= 0) {
			return JSONUtils.toJSONString(rows);
		} else {
			return "[]";
		}

	}

	/**
	 * android污水设备故障维修任务详情
	 * 
	 */
	@RequestMapping("/getSbgzwxDetail")
	@ResponseBody
	public String getSbgzwxDetail(String tableName, String taskCode) {
		if (tableName.isEmpty() || taskCode.isEmpty()) {
			return "[]";
		}
		tableName = tableName.toUpperCase();
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		String sql = "select t1.c_userealname,t.* from " + tableName + " t left join safe_user t1 on t.repair_person = t1.s_userid where t.task_id = '" + taskCode + "'";
		// parms.add(new GlobalParameter("tableName", tableName));
		// parms.add(new GlobalParameter("taskCode", taskCode));
		List<RowBase> rows = DataUtil.getSelectRows(sql, parms);
		if (rows != null && rows.size() >= 0) {
			return JSONUtils.toJSONString(rows);
		} else {
			return "[]";
		}

	}

	/**
	 * 污水日常巡检选项获取
	 */
	@RequestMapping("/getWsRcxjDetail")
	@ResponseBody
	public String getWsRcxjDetail(String tableName, String taskCode) {
		if (tableName.isEmpty() || taskCode.isEmpty()) {
			return "";
		}
		tableName = tableName.toUpperCase();
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		String fatherSql = "select S_DOMAINCODE \"id\",S_DOMAINCAPTION \"name\" from data_defulatdomain where S_DOMAINNAME = '运维项' and I_JB ='2' and S_DOMAINCODE like 'A1%' ORDER BY S_DOMAINCODE";
		// 1.获得一级目录
		List<RowBase> fatherList = DataUtil.getSelectRows(fatherSql, parms);

		// 响应结果
		List<HashMap<String, Object>> resultList = new ArrayList<HashMap<String, Object>>();
		if (null != fatherSql) {
			String id;
			String name;
			String childsql = "select t1.S_DOMAINCAPTION as name, t.item,t.ITEM_VALUE as value from " + tableName + " t left join  (select S_DOMAINCODE,S_DOMAINCAPTION  from data_defulatdomain where S_DOMAINNAME = '运维项' and I_JB ='3')t1  " + " on t.item = t1.S_DOMAINCODE  where t.task_code = '" + taskCode + "'";
			HashMap<String, Object> father;
			for (RowBase bean : fatherList) {
				String sql = null;
				id = bean.get("id").toString();
				name = bean.get("name").toString();
				sql = childsql + "and t.item like '" + id + "%' ORDER BY t.item desc";
				List<RowBase> childList = DataUtil.getSelectRows(sql, parms);
				father = new HashMap<String, Object>();
				father.put("id", id);
				father.put("name", name);
				father.put("childList", childList);
				resultList.add(father);
			}
			JSONArray jsonArray = JSONArray.fromObject(resultList);
			return jsonArray.toString();
		} else {
			return new JSONArray().toString();
		}
	}

	/**
	 * 污水定期维护选项获取
	 */
	@RequestMapping("/getWsDqwhDetail")
	@ResponseBody
	public String getWsDqwhDetail(String tableName, String taskCode) {
		if (tableName.isEmpty() || taskCode.isEmpty()) {
			return "";
		}
		tableName = tableName.toUpperCase();
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		String fatherSql = "select S_DOMAINCODE \"id\",S_DOMAINCAPTION \"name\" from data_defulatdomain where S_DOMAINNAME = '运维项' and I_JB ='2' and S_DOMAINCODE like 'A2%' ORDER BY S_DOMAINCODE";
		// 1.获得一级目录
		List<RowBase> fatherList = DataUtil.getSelectRows(fatherSql, parms);

		// 响应结果
		List<HashMap<String, Object>> resultList = new ArrayList<HashMap<String, Object>>();
		if (null != fatherSql) {
			String id;
			String name;
			String childsql = "select t1.S_DOMAINCAPTION as name, t.item,t.ITEM_VALUE as value from " + tableName + " t left join  (select S_DOMAINCODE,S_DOMAINCAPTION  from data_defulatdomain where S_DOMAINNAME = '运维项' and I_JB ='4')t1  " + " on t.item = t1.S_DOMAINCODE  where t.task_code = '" + taskCode + "' and t1.S_DOMAINCAPTION is not null ";
			HashMap<String, Object> father;
			for (RowBase bean : fatherList) {
				String sql = null;
				id = bean.get("id").toString();
				name = bean.get("name").toString();
				sql = childsql + "and t.item like '" + id + "%' ORDER BY t.item desc";
				List<RowBase> childList = DataUtil.getSelectRows(sql, parms);
				father = new HashMap<String, Object>();
				father.put("id", id);
				father.put("name", name);
				father.put("childList", childList);
				resultList.add(father);
			}
			JSONArray jsonArray = JSONArray.fromObject(resultList);
			return jsonArray.toString();
		} else {
			return new JSONArray().toString();
		}
	}

	/**
	 * android获取参数单位
	 * 
	 * @param userName
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/getUnit")
	@ResponseBody
	public String getUnit() {
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		String sql = "select t.S_DOMAINCODE,t.S_DOMAINCAPTION,t.s_unit from data_defulatdomain t where t.S_DOMAINNAME = 'MONITOR_PARAM'";
		List<RowBase> rows = DataUtil.getSelectRows(sql, parms);
		if (rows != null && rows.size() >= 0) {
			return JSONUtils.toJSONString(rows);
		} else {
			return "[]";
		}
	}

	/**
	 * android签到时间
	 * 
	 * @param userName
	 * @param password
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/getSignIn")
	@ResponseBody
	public String getSignIn(String userName, String scId) {
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();

		String sql = "select to_char(CT,'yyyy-mm-dd') as ct from (select  * from OP_REGI_INFO  where USER_ID = '" + userName + "' and WTTP_ID = '" + scId + "'and CT is not null order by CT desc) where rownum=1";
		List<RowBase> rows = DataUtil.getSelectRows(sql, parms);

		if (rows != null && rows.size() > 0) {
			String result = JSONUtils.toJSONString(rows);
			return result;
		} else {
			return "[]";
		}
	}

	/**
	 * android签到时间
	 * 
	 * @param userName
	 * @param password
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/getSignInResult")
	@ResponseBody
	public String getSignInResult(String token, String userID, String tableName, String row, String dataType, String TASK_CODE, String CREATE_TIME,
			String FINISH_BY, String DISTANCE) throws Exception {
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		if (null == DISTANCE || DISTANCE.isEmpty()) {
			return "{\"result\":false}";
		}
		String signInRange = PropertiesUnit.getValue("distance");
		if (Float.parseFloat(DISTANCE) <= Integer.parseInt(signInRange)) {
			String result = null;
			try {
				RowBase entity = JSONConvertUtils.convertToEntity(row);
				Object obj = entity.getValue("_IS_DOMAIN_TRUE");
				if (obj != null && obj.toString().toLowerCase().equals("true")) {
					result = null;
				} else {
					result = tableSave(tableName, entity);
					if (!TASK_CODE.isEmpty() && !TASK_CODE.equals("")) {
						updateTaskStatus(TASK_CODE, "1", CREATE_TIME, FINISH_BY);
					}

				}
			} catch (Exception e) {
				e.printStackTrace();
				throw e;
			}
			return "{\"result\":true}";
		}
		return "{\"result\":false}";

	}

	/**
	 * android移动运营获取站点所属水司
	 * 
	 * @param userName
	 * @param password
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/getWaterCompanyList")
	@ResponseBody
	public String getWaterCompanyList(String groupId) {
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		String sql = "select count(t1.exp_no)as num,t.name,t1.wwtp_id as s_id from BC_ENTERPRISE_ATTR t left join BC_SITE_INFO t1 " + "on t.exp_no = t1.wwtp_id left join OPERATION_GROUP_STATION_ASSO t2 on t1.exp_no = " + "t2.station_id where t1.STATION_CATEGORY = '3' and t.POLL_TYPE='3'";
		if (!groupId.isEmpty()) {
			sql += " and t2.OPERATION_GROUP_ID =@GUID ";
			parms.add(new GlobalParameter("GUID", groupId));
		}
		sql += " group by t.name,t1.wwtp_id";
		List<RowBase> rows = DataUtil.getSelectRows(sql, parms);

		if (rows != null && rows.size() > 0) {
			String result = JSONUtils.toJSONString(rows);
			return JSONUtils.toJSONString(rows);
		} else {
			return "";
		}
	}

	/**
	 * android移动运营供水核查人员名称
	 * 
	 * @param userName
	 * @param password
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/getGsXCKHHCName")
	@ResponseBody
	public String getGsXCKHHCName(String groupId) {
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		String sql = "select t.c_userealname,t.s_userid from (select u.s_userid,u.c_username,u.c_userealname," + "r.c_rolename from safe_user u left join safe_userrole ur on u.s_userid = " + "ur.s_userid left join safe_role r on r.i_roleid = ur.s_roleid ) t where t.c_rolename = '核查人员'";
		List<RowBase> rows = DataUtil.getSelectRows(sql, parms);
		if (rows != null && rows.size() > 0) {
			String result = JSONUtils.toJSONString(rows);
			return JSONUtils.toJSONString(rows);
		} else {
			return "[]";
		}
	}

	/**
	 * android移动运营初始化供水异常
	 * 
	 * @param userName
	 * @param password
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/initGsWarn")
	@ResponseBody
	public String initGsWarn(String groupId) {
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		String sql = null;
		if (StringUtils.IsNullOrSpace(groupId)) {
			sql = "select t1.s_domaincaption,t2.s_domaincaption,t3.name,t3.exp_no,t.alarm_value,t.alarm_text,to_char(t.START_TIME, 'yyyy-MM-dd HH24:MI:SS') as lastupdatetime,t.CONTINUE_TIME from OP_ALAR_INFO t\n" + "left join data_defulatdomain t1 on t.type = t1.s_domaincode\n" + "left join (select * from data_defulatdomain where S_DOMAINNAME = 'MONITOR_PARAM') t2 on t.param = t2.s_domaincode\n" + "left join BC_SITE_INFO t3 on t.station_code = t3.exp_no\n" + "left join  OPERATION_GROUP_STATION_ASSO t4 on t.station_code = t4.STATION_ID\n" + "where t.is_recover = '0'   and t1.S_DOMAINNAME = '报警类型'   and t3.STATION_CATEGORY = '3'   and continue_time is not null";
		} else {
			parms.add(new GlobalParameter("groupId", groupId));
			sql = "select t1.s_domaincaption,t2.s_domaincaption,t3.name,t3.exp_no,t.alarm_value,t.alarm_text,to_char(t.START_TIME, 'yyyy-MM-dd HH24:MI:SS') as lastupdatetime,t.CONTINUE_TIME from OP_ALAR_INFO t\n" + "left join data_defulatdomain t1 on t.type = t1.s_domaincode\n" + "left join (select * from data_defulatdomain where S_DOMAINNAME = 'MONITOR_PARAM') t2 on t.param = t2.s_domaincode\n" + "left join BC_SITE_INFO t3 on t.station_code = t3.exp_no\n" + "left join  OPERATION_GROUP_STATION_ASSO t4 on t.station_code = t4.STATION_ID\n" + "where t.is_recover = '0'   and t1.S_DOMAINNAME = '报警类型'   and t3.STATION_CATEGORY = '3'   and continue_time is not null and  t4.OPERATION_GROUP_ID = @groupId";
		}
		List<RowBase> rows = DataUtil.getSelectRows(sql, parms);
		if (rows != null && rows.size() > 0) {
			return JSONUtils.toJSONString(rows);
		} else {
			return "";
		}
	}

	/**
	 * 获取设备是否在线, 0正常、1超标、2异常、3故障
	 */
	@RequestMapping("/getGsIfOnline")
	@ResponseBody
	public String getGsIfOnline() {
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		String sqlmn = "select t1.device_num,t1.site_id from BC_COLLECTION_INFO t1," + " monitor_station t2 where t1.site_id = t2.exp_no and t2.station_category='3'";
		List<RowBase> rowmn = DataUtil.getSelectRows(sqlmn, parms);
		JSONObject jsonObj = new JSONObject();
		if (rowmn.size() > 0) {
			for (int i = 0; i < rowmn.size(); i++) {
				String mn = rowmn.get(i).getSafeString("DEVICE_NUM");
				String status = RedisHelper.getInstance().getStationStatus(mn);
				jsonObj.put(rowmn.get(i).getSafeString("site_id"), status);
			}
		}

		return JSONUtils.toJSONString(jsonObj);
		// String status = RedisHelper.getInstance().getStationStatus(mn);
	}

	/*
	 * 获取平台实时在线数值，按最新获取
	 */
	@RequestMapping("/getRealValue")
	@ResponseBody
	public String getRealValue(String stationId, String time) {
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		if (null == stationId || stationId.isEmpty()) {
			return "[]";
		}
		if (null == time || time.isEmpty()) {
			return "[]";

		}
		String sql = "select t1.site_id, to_char(t.datatime, 'yyyy-mm-dd hh24:mi:ss') as datatime ,t.mn,t.parmname,t.rtd from monitor_data t left join BC_COLLECTION_INFO t1 on t.mn = t1.device_num " + "where datatime = to_date(@time, 'yyyy-mm-dd hh24:mi:ss')  and t1.site_id = @stationId";

		parms.add(new GlobalParameter("stationId", stationId));
		parms.add(new GlobalParameter("time", time));

		List<RowBase> rows = DataUtil.getSelectRows(sql, parms);
		if (rows != null && rows.size() > 0) {
			String result = JSONUtils.toJSONString(rows);
			return JSONUtils.toJSONString(rows);
		} else {
			String sql1 = "select t1.site_id,\n" + "       @time as datatime,\n" + "       t.mn,\n" + "       t.parmname,\n" + "       t.rtd\n" + "  from monitor_data t\n" + "  left join BC_COLLECTION_INFO t1\n" + "    on t.mn = t1.device_num\n" + " where 1 = 1\n" + "   and t1.site_id = @stationId\n" + "   and datatime =\n" + "       (select max(t.DATATIME)\n" + "          from monitor_data t\n" + "          left join BC_COLLECTION_INFO t1\n" + "            on t.mn = t1.device_num\n" + "         where datatime >=\n" + "               to_date(@time, 'yyyy-mm-dd hh24:mi:ss') - 1\n" + "           and t1.site_id = @stationId)";
			parms.add(new GlobalParameter("stationId", stationId));
			parms.add(new GlobalParameter("time", time));

			List<RowBase> rows1 = DataUtil.getSelectRows(sql1, parms);
			if (rows1 != null && rows1.size() > 0) {
				String result = JSONUtils.toJSONString(rows1);
				return JSONUtils.toJSONString(rows1);
			}
		}
		return "[]";
	}

	/*
	 * 获取平台实时在线数值，按实时获取
	 */
	@RequestMapping("/getRealValue1")
	@ResponseBody
	public String getRealValue1(String stationId, String time) {
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		String sql = "select t1.site_id,to_char(t.datatime,'yyyy-mm-dd hh24:mi:ss')as datatime,t.mn,t.parmname,t.rtd from monitor_data t " + "left join BC_COLLECTION_INFO t1 on t.mn = t1.device_num where 1=1";
		if (null != stationId && !stationId.isEmpty()) {
			sql += " and t1.site_id = @stationId ";
			parms.add(new GlobalParameter("stationId", stationId));
		}
		if (null != time && !time.isEmpty()) {
			sql += " and datatime = to_date(@time,'yyyy-mm-dd hh24:mi:ss') ";
			parms.add(new GlobalParameter("time", time));
		}
		List<RowBase> rows = DataUtil.getSelectRows(sql, parms);
		if (rows != null && rows.size() > 0) {
			String result = JSONUtils.toJSONString(rows);
			return JSONUtils.toJSONString(rows);
		} else {
			String sql1 = "select t1.site_id,to_char(t.datatime,'yyyy-mm-dd hh24:mi:ss')as datatime,t.mn,t.parmname,t.rtd from monitor_data t " + "left join BC_COLLECTION_INFO t1 on t.mn = t1.device_num where 1=1";
			if (null != stationId && !stationId.isEmpty()) {
				sql1 += " and t1.site_id = @stationId ";
				parms.add(new GlobalParameter("stationId", stationId));
			}
			if (null != stationId && !stationId.isEmpty()) {
				sql1 += " and datatime = to_date(@time,'yyyy-mm-dd hh24:mi:ss')";
				Date rtn = null;
				GregorianCalendar cal = new GregorianCalendar();
				Date date = null;
				try {
					SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
					date = sdf.parse(time);
				} catch (ParseException e) {
					System.out.println(e.getMessage());
				}
				cal.setTime(date);
				cal.add(12, -5);
				Date lasttime = cal.getTime();
				SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
				String str = sdf.format(lasttime);
				parms.add(new GlobalParameter("time", str));
			}
			List<RowBase> rows1 = DataUtil.getSelectRows(sql1, parms);
			if (rows1 != null && rows1.size() > 0) {
				String result = JSONUtils.toJSONString(rows1);
				return JSONUtils.toJSONString(rows1);
			} else {
				return "[]";
			}
		}
	}

	/**
	 * 获取人员和签名照路径
	 */
	@RequestMapping("/getSignatureUrl")
	@ResponseBody
	public String getSignatureUrl() {
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		String sql = "select t.c_userealname,t.s_orgid,t.s_userid,t.sign_img from safe_user t";
		List<RowBase> rows = DataUtil.getSelectRows(sql, parms);
		if (rows != null && rows.size() > 0) {
			String result = JSONUtils.toJSONString(rows);
			return JSONUtils.toJSONString(rows);
		} else {
			return "[]";
		}
	}

	/**
	 * 获取上次维护时间
	 */
	@RequestMapping("/getLastWhDate")
	@ResponseBody
	public String getLastWhDate(String stationId) {
		if (stationId.isEmpty()) {
			return "[]";
		}
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		String sql = "select to_char(t.ASSERTTIME,'yyyy-MM-dd HH24:MI:SS')as ASSERTTIME from BC_SITE_INFO t where exp_no = @stationId";
		parms.add(new GlobalParameter("stationId", stationId));
		List<RowBase> rows = DataUtil.getSelectRows(sql, parms);
		if (rows != null && rows.size() > 0) {
			String result = JSONUtils.toJSONString(rows);
			return JSONUtils.toJSONString(rows);
		} else {
			return "[]";
		}
	}

	/**
	 * 保存一致性数据
	 * 
	 * @return 0：保存失败
	 */
	@RequestMapping("/saveSignatureData")
	@ResponseBody
	public String saveSignatureData(String row, String stationId, String DATETIME, String userID, String THANDATE, String ASSERTTIME) {
		// 默认返回保存失败
		JSONObject resultJson = new JSONObject();
		resultJson.put("result", "0");
		if (row.isEmpty() || stationId.isEmpty() || DATETIME.isEmpty() || userID.isEmpty()) {
			// 参数不合法，保存失败
			return resultJson.toString();
		}

		Date date = null;
		Date tdate = null;
		try {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			tdate = sdf.parse(THANDATE);
			date = sdf.parse(DATETIME);
		} catch (ParseException e) {
			System.out.println(e.getMessage());
		}
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		parms.add(new GlobalParameter("STATIONID", stationId));
		parms.add(new GlobalParameter("USERID", userID));
		parms.add(new GlobalParameter("THANDATE", tdate));
		parms.add(new GlobalParameter("DATETIME", date));
		String querySql = "select STATIONID from COHERENCEDATA " + "WHERE DATETIME = @DATETIME AND STATIONID = @STATIONID AND USERID = @USERID";
		List<RowBase> rows = DataUtil.getSelectRows(querySql, parms);
		if (rows != null && rows.size() > 0) {
			// 表示重复保存，保存失败
			return resultJson.toString();
		}
		if (null != ASSERTTIME && !ASSERTTIME.isEmpty()) {
			Date tdate_1 = null;
			try {
				SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
				tdate_1 = sdf.parse(ASSERTTIME);
			} catch (ParseException e) {
				System.out.println(e.getMessage());
			}
			String whSql = "update monitor_station set ASSERTTIME = @tdate where exp_no = @stationId";
			parms.add(new GlobalParameter("tdate", tdate_1));
			parms.add(new GlobalParameter("stationId", stationId));
			int i = DataUtil.ExecuteUpdateSql(whSql, parms);
			if (i != 0) {
				return resultJson.toString();
			}
		}
		JSONArray list = JSONUtils.toJSONArray(row);
		int f = 0;
		for (int i = 0; i < list.size(); i++) {
			String PARMNAME = list.getJSONObject(i).optString("PARMNAME");
			String RTD = list.getJSONObject(i).optString("RTD");
			String VALUE = list.getJSONObject(i).optString("VALUE");
			String Sql = "insert into COHERENCEDATA(PARMNAME,RTD,VALUE,STATIONID,DATETIME,USERID,THANDATE) values " + "(@PARMNAME,@RTD,@VALUE,@STATIONID,@DATETIME,@USERID,@THANDATE)";
			parms.add(new GlobalParameter("PARMNAME", PARMNAME));
			parms.add(new GlobalParameter("RTD", RTD));
			parms.add(new GlobalParameter("VALUE", VALUE));
			f = f + DataUtil.ExecuteUpdateSql(Sql, parms);
		}
		if (f == 0) {
			resultJson.put("result", "1");
		}
		return resultJson.toString();
	}

	/**
	 * 获取当天现场考核历史数据
	 */
	@RequestMapping("/getXCKHData")
	@ResponseBody
	public String getXCKHData(String stationId, String userId) {
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		if (stationId.isEmpty() || userId.isEmpty()) {
			return "[]";
		}
		String sql1 = "select t1.c_userealname as jcname,t2.c_userealname as hcname,t3.c_userealname as gsname,t.* from  SUPPLY_WATER_STATION_CHECK t " + " left join safe_user t1 on t1.s_userid = t.inspector_userid " + " left join safe_user t2 on t2.s_userid = t.Inspect_Id " + " left join safe_user t3 on t3.s_userid = t.COMPANY_USERID  where t.station_code = '" + stationId + "' " + " and t.inspector_userid ='" + userId + "'and  to_char(t.check_date,'yyyy-mm-dd') = to_char(sysdate,'yyyy-mm-dd')";
		List<RowBase> rows1 = DataUtil.getSelectRows(sql1, parms);
		JSONArray jsonObj = new JSONArray();
		for (int i = 0; i < rows1.size(); i++) {
			JSONObject chidlobject = new JSONObject();
			String childGuid = rows1.get(i).getSafeString("GUID");
			String sql = "select t1.S_DOMAINCAPTION as equipmentName,t.* from SUPPLY_WATER_STATION_CHECKITEM t " + "left join (select t.S_DOMAINCODE,t.S_DOMAINCAPTION  from data_defulatdomain  t " + "where S_DOMAINNAME='检测设备代号' )t1 on t1.s_domaincode = t.poll_code where check_id = '" + childGuid + "'";
			List<RowBase> rows = DataUtil.getSelectRows(sql, parms);
			chidlobject.put("parent", rows1.get(i));
			chidlobject.put("child", rows);
			jsonObj.add(chidlobject);
		}
		// String sql = "select t.*,t2.* from SUPPLY_WATER_STATION_CHECK t left
		// join "
		// + "SUPPLY_WATER_STATION_CHECKITEM t2 on t.guid=t2.check_id where
		// t.station_code = '" + stationId + "' "
		// + "and t.inspector_userid ='"+ userId +"'and
		// to_char(t.check_date,'yyyy-mm-dd') = to_char(sysdate,'yyyy-mm-dd')";
		// List<RowBase> rows = DataUtil.getSelectRows(sql, parms);
		if (jsonObj != null && jsonObj.size() > 0) {
			return JSONUtils.toJSONString(jsonObj.toString());
		} else {
			return "[]";
		}
	}

	/**
	 * 获取供水公司人员名称
	 */
	@RequestMapping("/getGsXCKHGSName")
	@ResponseBody
	public String getGsXCKHGSName() {
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		String sql = "select t.c_userealname,t.s_userid from (select u.s_userid,u.c_username,u.c_userealname," + "r.c_rolename from safe_user u left join safe_userrole ur on u.s_userid = " + "ur.s_userid left join safe_role r on r.i_roleid = ur.s_roleid ) t where t.c_rolename = '公司运营人员'";
		List<RowBase> rows = DataUtil.getSelectRows(sql, parms);
		if (rows != null && rows.size() > 0) {
			String result = JSONUtils.toJSONString(rows);
			return JSONUtils.toJSONString(rows);
		} else {
			return "[]";
		}
	}

	/**
	 * android供水现场考核数据保存
	 */
	@RequestMapping("/saveGSXCKHData")
	@ResponseBody
	public String saveGSXCKHData(String saveData, String listMap) {
		RowBase entity = JSONConvertUtils.convertToEntity(saveData);
		JSONObject data = JSONUtils.toJSONObject(saveData);
		JSONArray list = JSONUtils.toJSONArray(listMap);
		// 如果存在则更新
		if (null != data.optString("STATION_CODE") && null != data.get("CHECK_DATE")) {
			List<GlobalParameter> mainParms = new ArrayList();
			String selectSql = "select * from SUPPLY_WATER_STATION_CHECK t where t.station_code = @STATION_CODE and  t.check_date = @CHECK_DATE";
			mainParms.add(new GlobalParameter("STATION_CODE", data.optString("STATION_CODE")));
			Date date = null;
			try {
				date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(data.optString("CHECK_DATE"));
			} catch (ParseException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			mainParms.add(new GlobalParameter("CHECK_DATE", date));
			List<RowBase> rows = DataUtil.getSelectRows(selectSql, mainParms);
			if (rows != null && rows.size() >= 1) {
				JSONArray jsonArray = JSONArray.fromObject(rows);
				String GUID1 = jsonArray.getJSONObject(0).optString("GUID");
				String savesql = "update SUPPLY_WATER_STATION_CHECK  set IS_DATA_TRAN_WORK = @IS_DATA_TRAN_WORK," + " IS_HOUSE_CLEAN = @IS_HOUSE_CLEAN,IS_OPERATION_WORK=@IS_OPERATION_WORK," + " CHECK_POINT=@CHECK_POINT,NOTE=@NOTE,INSPECTOR_USERID=@INSPECTOR_USERID," + " COMPANY_USERID=@COMPANY_USERID,CHECK_STATUS=@CHECK_STATUS,INSPECT_ID=@INSPECT_ID,TOTALMACHINE=@TOTALMACHINE," + " CHLORINEDIOXIDE=@CHLORINEDIOXIDE,TURBIDITYMETER=@TURBIDITYMETER,PHMACHINE=@PHMACHINE,COMMUNICATION=@COMMUNICATION," + " UPS=@UPS where station_code = @STATION_CODE and check_date = @CHECK_DATE ";

				mainParms.add(new GlobalParameter("STATION_CODE", data.optString("STATION_CODE")));
				mainParms.add(new GlobalParameter("IS_DATA_TRAN_WORK", data.optString("IS_DATA_TRAN_WORK")));
				mainParms.add(new GlobalParameter("IS_HOUSE_CLEAN", data.optString("IS_HOUSE_CLEAN")));
				mainParms.add(new GlobalParameter("IS_OPERATION_WORK", data.optString("IS_OPERATION_WORK")));
				// 1次8月1次7月1次1月 在月后面加了空格 转成1次8月 1次7月 1次1月
				mainParms.add(new GlobalParameter("OPERATION_FREQUENCY", toSpaceSplitString(data.optString("OPERATION_FREQUENCY"))));
				mainParms.add(new GlobalParameter("COMPARED_FREQUENCY", toSpaceSplitString(data.optString("COMPARED_FREQUENCY"))));
				mainParms.add(new GlobalParameter("CHECK_POINT", data.optString("CHECK_POINT")));
				mainParms.add(new GlobalParameter("NOTE", data.optString("NOTE")));
				mainParms.add(new GlobalParameter("CHECK_STATUS", "3"));
				mainParms.add(new GlobalParameter("TOTALMACHINE", data.optString("TOTALMACHINE")));
				mainParms.add(new GlobalParameter("CHLORINEDIOXIDE", data.optString("CHLORINEDIOXIDE")));
				mainParms.add(new GlobalParameter("TURBIDITYMETER", data.optString("TURBIDITYMETER")));
				mainParms.add(new GlobalParameter("PHMACHINE", data.optString("PHMACHINE")));
				mainParms.add(new GlobalParameter("COMMUNICATION", data.optString("COMMUNICATION")));
				mainParms.add(new GlobalParameter("UPS", data.optString("UPS")));
				SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd ");
				mainParms.add(new GlobalParameter("CHECK_DATE", date));
				mainParms.add(new GlobalParameter("INSPECTOR_USERID", data.optString("INSPECTOR_USERID")));
				mainParms.add(new GlobalParameter("INSPECT_ID", data.optString("INSPECT_ID")));
				mainParms.add(new GlobalParameter("COMPANY_USERID", data.optString("COMPANY_USERID")));
				int i = DataUtil.ExecuteUpdateSql(savesql, mainParms);
				for (int j = 0; j < list.size(); j++) {
					String sql = "update SUPPLY_WATER_STATION_CHECKITEM set EQUIPMENT_VALUE = @EQUIPMENT_VALUE,STANDARD_VALUE = @STANDARD_VALUE," + "IS_PASS = @IS_PASS,RTD = @RTD where CHECK_ID = @GUID1 and POLL_CODE = @POLL_CODE";
					List<GlobalParameter> childparms = new ArrayList();

					childparms.add(new GlobalParameter("GUID1", GUID1));
					childparms.add(new GlobalParameter("POLL_CODE", list.getJSONObject(j).optString("POLL_CODE")));
					try {
						childparms.add(
								new GlobalParameter("EQUIPMENT_VALUE", Float.parseFloat(list.getJSONObject(j).optString("EQUIPMENT_VALUE"))));
					} catch (Exception e) {
						childparms.add(new GlobalParameter("EQUIPMENT_VALUE", null));
					}
					try {
						childparms
								.add(new GlobalParameter("STANDARD_VALUE", Float.parseFloat(list.getJSONObject(j).optString("STANDARD_VALUE"))));
					} catch (Exception e) {
						childparms.add(new GlobalParameter("STANDARD_VALUE", null));
					}
					try {
						childparms.add(new GlobalParameter("RTD", Float.parseFloat(list.getJSONObject(j).optString("RTD"))));
					} catch (Exception e) {
						childparms.add(new GlobalParameter("RTD", null));
					}

					childparms.add(new GlobalParameter("IS_PASS", list.getJSONObject(j).optString("IS_PASS")));
					i = i + DataUtil.ExecuteUpdateSql(sql, childparms);
				}
				if (i == 0) {
					return "{\"result\":true}";
				} else {
					return "{\"result\":false}";
				}
			} else {

				String savesql = "insert into SUPPLY_WATER_STATION_CHECK(GUID,STATION_CODE,IS_DATA_TRAN_WORK,IS_HOUSE_CLEAN,IS_OPERATION_WORK" + ",CHECK_POINT,NOTE,CHECK_DATE,INSPECTOR_USERID,COMPANY_USERID,CHECK_STATUS,INSPECT_ID," + "TOTALMACHINE,CHLORINEDIOXIDE,TURBIDITYMETER,PHMACHINE,COMMUNICATION,UPS)values" + "(@GUID,@STATION_CODE,@IS_DATA_TRAN_WORK,@IS_HOUSE_CLEAN,@IS_OPERATION_WORK," + "@CHECK_POINT,@NOTE,@CHECK_DATE,@INSPECTOR_USERID,@COMPANY_USERID,@CHECK_STATUS,@INSPECT_ID," + "@TOTALMACHINE,@CHLORINEDIOXIDE,@TURBIDITYMETER,@PHMACHINE,@COMMUNICATION,@UPS)";

				List<GlobalParameter> parms = new ArrayList();
				String GUID = UUID.randomUUID().toString();
				parms.add(new GlobalParameter("GUID", GUID));
				parms.add(new GlobalParameter("STATION_CODE", data.optString("STATION_CODE")));
				parms.add(new GlobalParameter("IS_DATA_TRAN_WORK", data.optString("IS_DATA_TRAN_WORK")));
				parms.add(new GlobalParameter("IS_HOUSE_CLEAN", data.optString("IS_HOUSE_CLEAN")));
				parms.add(new GlobalParameter("IS_OPERATION_WORK", data.optString("IS_OPERATION_WORK")));
				// 1次8月1次7月1次1月 在月后面加了空格 转成1次8月 1次7月 1次1月
				parms.add(new GlobalParameter("OPERATION_FREQUENCY", toSpaceSplitString(data.optString("OPERATION_FREQUENCY"))));
				parms.add(new GlobalParameter("COMPARED_FREQUENCY", toSpaceSplitString(data.optString("COMPARED_FREQUENCY"))));
				parms.add(new GlobalParameter("CHECK_POINT", data.optString("CHECK_POINT")));
				parms.add(new GlobalParameter("NOTE", data.optString("NOTE")));
				parms.add(new GlobalParameter("CHECK_STATUS", "3"));
				parms.add(new GlobalParameter("TOTALMACHINE", data.optString("TOTALMACHINE")));
				parms.add(new GlobalParameter("CHLORINEDIOXIDE", data.optString("CHLORINEDIOXIDE")));
				parms.add(new GlobalParameter("TURBIDITYMETER", data.optString("TURBIDITYMETER")));
				parms.add(new GlobalParameter("PHMACHINE", data.optString("PHMACHINE")));
				parms.add(new GlobalParameter("COMMUNICATION", data.optString("COMMUNICATION")));
				parms.add(new GlobalParameter("UPS", data.optString("UPS")));
				SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd ");
				// Date date = null;
				parms.add(new GlobalParameter("CHECK_DATE", date));
				parms.add(new GlobalParameter("INSPECTOR_USERID", data.optString("INSPECTOR_USERID")));
				parms.add(new GlobalParameter("INSPECT_ID", data.optString("INSPECT_ID")));
				parms.add(new GlobalParameter("COMPANY_USERID", data.optString("COMPANY_USERID")));
				int i = DataUtil.ExecuteUpdateSql(savesql, parms);
				for (int j = 0; j < list.size(); j++) {
					String sql = "insert into SUPPLY_WATER_STATION_CHECKITEM(GUID,CHECK_ID,POLL_CODE,EQUIPMENT_VALUE,STANDARD_VALUE,IS_PASS,RTD) values" + "(@GUID,@CHECK_ID,@POLL_CODE,@EQUIPMENT_VALUE,@STANDARD_VALUE,@IS_PASS,@RTD)";
					List<GlobalParameter> childparms = new ArrayList();
					String GUID1 = UUID.randomUUID().toString();
					childparms.add(new GlobalParameter("GUID", GUID1));
					childparms.add(new GlobalParameter("CHECK_ID", GUID));
					childparms.add(new GlobalParameter("POLL_CODE", list.getJSONObject(j).optString("POLL_CODE")));
					try {
						childparms.add(
								new GlobalParameter("EQUIPMENT_VALUE", Float.parseFloat(list.getJSONObject(j).optString("EQUIPMENT_VALUE"))));
					} catch (Exception e) {
						childparms.add(new GlobalParameter("EQUIPMENT_VALUE", null));
					}
					try {
						childparms
								.add(new GlobalParameter("STANDARD_VALUE", Float.parseFloat(list.getJSONObject(j).optString("STANDARD_VALUE"))));
					} catch (Exception e) {
						childparms.add(new GlobalParameter("STANDARD_VALUE", null));
					}
					childparms.add(new GlobalParameter("IS_PASS", list.getJSONObject(j).optString("IS_PASS")));
					childparms.add(new GlobalParameter("RTD", list.getJSONObject(j).optString("RTD")));
					i = i + DataUtil.ExecuteUpdateSql(sql, childparms);
				}
				if (i == 0) {
					return "{\"result\":true}";
				} else {
					return "{\"result\":false}";
				}
			}
		} else {
			return "{\"result\":false}";
		}

	}

	// 供水 1次8月1次7月1次1月 在月后面增加两个空格
	private String toSpaceSplitString(String text) {
		if (text == null || text.trim().length() == 0) {
			return "";
		}
		List<String> list = new ArrayList<>();
		for (int index = 0, startIndex = 0; index < text.length(); index++) {
			if ("月".equals(String.valueOf(text.charAt(index)))) {
				list.add(text.substring(startIndex, index + 1));
				startIndex = index + 1;
			}
		}
		if (list.size() > 0) {
			String result = "";
			for (String string : list) {
				result += string + ",";
			}
			return result.substring(0, result.length() - 1);
		} else {
			return text;
		}
	}

	/**
	 * android移动运营获取定期维护详情
	 * 
	 * @param task_code
	 *            任务编号
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/getDQWHdetailData")
	@ResponseBody
	public String getDQWHdetailData(String task_code) {
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		String sql = "select t.item_value ,t.item ,t1.s_domaincaption ," + " decode(t.item_value,0,'-',1,to_char(t2.start_time,'yyyy-MM-dd HH24:MI:SS'))" + " as stime,decode(t.item_value,0,'-',1,to_char(t2.end_time,'yyyy-MM-dd HH24:MI:SS'))" + " as etime ,decode(t.item_value,0,'-',1,to_char(t2.finish_time,'yyyy-MM-dd HH24:MI:SS'))" + " as ftime from OPERATION_RECORD_MAINTAINANCE t left join" + "  data_defulatdomain t1 on t.item = t1.s_domaincode left join" + " operation_task t2 on t.task_code = t2.task_code  where t1.s_domainname ='供水运维项' ";
		if (!task_code.isEmpty()) {
			sql += " and t.task_code = @task_code ";
			parms.add(new GlobalParameter("task_code", task_code));
		}

		sql += "order by t.item asc";
		List<RowBase> rows = DataUtil.getSelectRows(sql, parms);
		JSONArray array = JSONArray.fromObject(rows);
		if (rows != null && rows.size() >= 0) {
			Object[] array1 = rows.toArray();
			return JSONUtils.toJSONString(rows);
		} else {
			return "";
		}
	}

	/**
	 * android移动运营更新详情
	 * 
	 * @param task_code
	 *            任务编号
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/updateDQWHdetailData")
	@ResponseBody
	public String updateDQWHdetailData(String vulue, String flag, String task_code) {
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		if (vulue.isEmpty() || flag.isEmpty()) {
			return "";
		}
		String sql = "update OPERATION_RECORD_MAINTAINANCE set  ";
		sql += " ITEM_VALUE= @ITEM_VALUE where ITEM='" + flag + "' ";
		parms.add(new GlobalParameter("ITEM_VALUE", Integer.parseInt(vulue)));
		if (!task_code.isEmpty()) {
			sql += " and TASK_CODE = @task_code ";
			parms.add(new GlobalParameter("task_code", task_code));
		}
		int i = DataUtil.ExecuteUpdateSql(sql, parms);
		if (i == 0) {
			return "{\"result\":true}";
		} else {
			return "{\"result\":false}";
		}
	}

	/**
	 * android获取任务表站点唯一编号
	 * 
	 * @param userName
	 * @param password
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/getTastStationNo")
	@ResponseBody
	public String getTastStationNo(String gcId, String tag) {
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();

		String sql = "select exp_no from BC_SITE_INFO where wwtp_id='" + gcId + "' and flow_type='" + tag + "'";
		List<RowBase> rows = DataUtil.getSelectRows(sql, parms);

		if (rows != null && rows.size() > 0) {
			String result = JSONUtils.toJSONString(rows);
			return JSONUtils.toJSONString(rows);
		} else if (rows.toString().equals("[]")) {
			return "[]";
		} else {
			return "";
		}
	}

	/**
	 * 登录 wangl
	 * 
	 * @param userName
	 * @param password
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/login")
	@ResponseBody
	public String login(String userName, String password) throws Exception {
		checkToken(token);
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		String sql = "select t1.C_USERNAME,t1.C_USEREALNAME,t3.GROUP_NAME,t1.PHOTO,t1.s_userid,t3.guid as group_id  from safe_user " + "t1 left join OC_GROUP_ASSO t2 on t1.s_userid=t2.user_id " + "left join OC_GROUP t3 on t2.group_id=t3.guid where 1=1 ";
		if (userName != null && !userName.equals("")) {
			sql += " and t1.c_username =@userName";
			parms.add(new GlobalParameter("userName", userName));
		}
		if (password != null && !password.equals("")) {
			sql += " and t1.C_PWD =@password";
			parms.add(new GlobalParameter("password", password));
		}
		List<RowBase> rows = DataUtil.getSelectRows(sql, parms);
		JSONObject jo = new JSONObject();
		if (rows != null && rows.size() > 0) {
			String uid = rows.get(0).getValue("C_USERNAME").toString();
			String uname = rows.get(0).getValue("C_USEREALNAME").toString();
			String GROUP_NAME = "";
			if (rows.get(0).getValue("GROUP_NAME") != null) {
				GROUP_NAME = rows.get(0).getValue("GROUP_NAME").toString();
			}
			String GROUP_ID = "";
			if (rows.get(0).getValue("GROUP_ID") != null) {
				GROUP_ID = rows.get(0).getValue("GROUP_ID").toString();
			}
			String S_USERID = rows.get(0).getValue("S_USERID").toString();

			String pic = "";
			if (rows.get(0).getValue("PHOTO") != null) {
				pic = rows.get(0).getValue("PHOTO").toString();
			}
			jo.put("UserName", uname);
			jo.put("UserID", uid);
			jo.put("GroupName", GROUP_NAME);
			jo.put("pic", pic);
			jo.put("S_USERID", S_USERID);
			jo.put("GROUP_ID", GROUP_ID);
		} else {
			jo.put("UserName", "");
			jo.put("UserID", "");
			jo.put("GroupName", "");
			jo.put("pic", "");
			jo.put("S_USERID", "");
			jo.put("GROUP_ID", "");
		}
		// initUserRole(rows.get(0));
		return JSONUtils.toJSONString(jo);
	}

	/**
	 * 解决用户登录后的session和数据权限等问题
	 * 
	 * @param row
	 *            陈旭
	 */
	private void initUserRole(RowBase row) {
		UserEntity userEntity = new UserEntity();
		userEntity.putAll(row);
		SessionFactory.getSession().setObject(ISessionProvider.UserEntity, userEntity);
		RoleInitHelper.getRoles(userEntity);
	}

	/**
	 * 获取用户所运维的污水厂 wangl
	 * 
	 * @param userID
	 *            用户ID
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/getWsclcData")
	@ResponseBody
	public String getWsclcData(String userID, String groupId) throws Exception {
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		String sql = "";
		if (groupId != null && !groupId.equals("")) {
			sql = "select sum(t.sum) as sum, t.name, t.exp_no\n" + "  from (select sum(t.sum) as sum, t.name, t.exp_no\n" + "          from (select t1.name,\n" + "                       t1.exp_no,\n" + "                       (case t7.task_status\n" + "                         when '0' then\n" + "                          1\n" + "                         else\n" + "                          0\n" + "                       end) as sum,\n" + "                       t7.task_status\n" + "                  from BC_ENTERPRISE_ATTR t1\n" + "                  left join BC_SITE_INFO t2 on t1.exp_no = t2.wwtp_id\n" + "                  left join OPERATION_GROUP_STATION_ASSO t3 on t2.exp_no =\n" + "                                                               t3.station_id\n" + "                  left join OC_GROUP t4 on t3.operation_group_id =\n" + "                                                  t4.guid\n" + "                  left join OPERATION_TASK t7 on t3.station_id =\n" + "                                                 t7.station_id\n" + "                 where 1 = 1\n" + "                   and t2.station_category = '0'\n" + "                   and t4.guid = '" + groupId + "') t\n" + "         where 1 = 1\n" + "         group by t.name, t.exp_no\n" + "        union all\n" + "        select count(*) as sum, t3.name as name, t3.exp_no\n" + "          from OP_ALAR_INFO t1\n" + "          left join BC_SITE_INFO t2 on t1.station_code = t2.exp_no\n" + "          left join BC_ENTERPRISE_ATTR t3 on t2.wwtp_id = t3.exp_no\n" + "          left join OPERATION_GROUP_STATION_ASSO t4 on t4.station_id =\n" + "                                                       t2.exp_no\n" + "          left join OC_GROUP t5 on t4.operation_group_id = t5.guid\n" + "         where t1.status = '0'\n" + "           and t1.is_recover = '0'\n" + "           and t2.station_category = '0'\n" + "           and t5.guid = '" + groupId + "'\n" + "         group by t3.exp_no, t3.name) t\n" + " group by t.exp_no, t.name";

		} else {
			sql = "select sum(t.sum) as sum, t.name, t.exp_no\n" + "  from (select sum(t.sum) as sum, t.name, t.exp_no\n" + "          from (select t1.name,\n" + "                       t1.exp_no,\n" + "                       (case t7.task_status\n" + "                         when '0' then\n" + "                          1\n" + "                         else\n" + "                          0\n" + "                       end) as sum,\n" + "                       t7.task_status\n" + "                  from BC_ENTERPRISE_ATTR t1\n" + "                  left join BC_SITE_INFO t2 on t1.exp_no = t2.wwtp_id\n" + "                  left join OPERATION_GROUP_STATION_ASSO t3 on t2.exp_no =\n" + "                                                               t3.station_id\n" + "                  left join OC_GROUP t4 on t3.operation_group_id =\n" + "                                                  t4.guid\n" + "                  left join OPERATION_TASK t7 on t3.station_id =\n" + "                                                 t7.station_id\n" + "                 where 1 = 1\n" + "                   and t2.station_category = '0') t\n" + "         where 1 = 1\n" + "         group by t.name, t.exp_no\n" + "        union all\n" + "        select count(*) as sum, t3.name as name, t3.exp_no\n" + "          from OP_ALAR_INFO t1\n" + "          left join BC_SITE_INFO t2 on t1.station_code = t2.exp_no\n" + "          left join BC_ENTERPRISE_ATTR t3 on t2.wwtp_id = t3.exp_no\n" + "         where t1.status = '0'\n" + "           and t2.station_category = '0'\n" + "           and t1.is_recover = '0'\n" + "         group by t3.exp_no, t3.name) t\n" + " group by t.exp_no, t.name";

		}

		List<RowBase> rows = DataUtil.getSelectRows(sql, parms);
		if (rows != null && rows.size() >= 0) {
			return JSONUtils.toJSONString(rows);
		} else {
			return "";
		}
	}

	/**
	 * 获取运维任务 wanl
	 */
	@RequestMapping("/getTaskById")
	@ResponseBody
	public String getTaskById(String wwtp_id, String flowType) {
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		List<GlobalParameter> parmyccz = new ArrayList<GlobalParameter>();
		String sql = "select t2.job_name,t1.task_code,t1.station_id,t3.flow_type,t2.guid as job_id from OP_TASK t1 " + "left join operation_job t2 on t2.guid=t1.job_id " + "left join  monitor_station t3 on t3.exp_no=t1.station_id where 1=1 and t1.task_status='0' ";
		// 获取是否有异常处置任务
		String sqlyccz = "select t2.flow_type,\n" + "       t1.station_code,\n" + "       t1.type as task_code,\n" + "       'yccz110' as job_id,\n" + "       '异常处置' as job_name\n" + "  from OP_ALAR_INFO t1\n" + "  left join BC_SITE_INFO t2 on t1.station_code = t2.exp_no\n" + " where 1 = 1 and t1.status = '0' ";
		if (wwtp_id != null && !wwtp_id.equals("")) {
			sql += " and t3.wwtp_id =@wwtp_id";
			parms.add(new GlobalParameter("wwtp_id", wwtp_id));
			sqlyccz += " and t2.wwtp_id =@wwtp_id";
			parmyccz.add(new GlobalParameter("wwtp_id", wwtp_id));
		}
		if (flowType != null && !flowType.equals("")) {
			sql += " and t3.flow_type =@flowType";
			parms.add(new GlobalParameter("flowType", flowType));
			sqlyccz += " and t2.flow_type =@flowType";
			parmyccz.add(new GlobalParameter("flowType", flowType));
		}
		List<RowBase> rows = DataUtil.getSelectRows(sql, parms);
		List<RowBase> rowyccz = DataUtil.getSelectRows(sqlyccz, parmyccz);
		if (rowyccz != null && rowyccz.size() > 0) {
			RowBase i = rowyccz.get(0);
			RowBase ycczData = new RowBase();
			ycczData.put("TASK_CODE", "yccz110");
			ycczData.put("JOB_NAME", "异常处置");
			ycczData.put("STATION_ID", i.get("STATION_CODE").toString());
			ycczData.put("FLOW_TYPE", flowType);
			ycczData.put("JOB_ID", "123456");
			rows.add(ycczData);
		}
		// rows.add(arg0)
		if (rows != null && rows.size() >= 0) {
			return JSONUtils.toJSONString(rows);
		} else {
			return "";
		}
	}

	/**
	 * 更新任务状态 wangl
	 * 
	 * @param TASK_CODE
	 * @param TASK_STATUS
	 * @param CREATE_TIME
	 * @return
	 */
	@RequestMapping("/updateTaskStatus")
	@ResponseBody
	public String updateTaskStatus(String TASK_CODE, String TASK_STATUS, String CREATE_TIME, String FINISH_BY) {
		String sql = "update  OPERATION_TASK set task_status='1',CREATE_TIME=to_date('" + CREATE_TIME + "','yyyy-mm-dd hh24:mi:ss'),FINISH_TIME=to_date('" + CREATE_TIME + "','yyyy-mm-dd hh24:mi:ss')" + ",FINISH_BY='" + FINISH_BY + "'" + " where task_code='" + TASK_CODE + "' ";
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		int i = DataUtil.ExecuteUpdateSql(sql, parms);
		if (i == 0) {
			return "{\"result\":true}";
		} else {
			return "{\"result\":false}";
		}

	}

	private void checkToken(String token) {
		if (!ObjectUtils.equals(token, this.token)) {
			throw new RuntimeException("认证错误！");
		}
	}

	/**
	 * 获取字典值 wangl
	 * 
	 * @param S_DOMAINNAME
	 * @return
	 */
	@RequestMapping("/getDataDefulatdomain")
	@ResponseBody
	public String getDataDefulatdomain(String S_DOMAINNAME) {
		String sql = "select S_DOMAINCODE,S_DOMAINNAME,s_domaincaption,PY_PREFIX from DATA_DEFULATDOMAIN where 1=1 and  S_DOMAINNAME is not null   ";// and
																																						// s_ischild='1'
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		if (S_DOMAINNAME != null && !S_DOMAINNAME.equals("")) {
			sql += " and S_DOMAINNAME =@S_DOMAINNAME";
			parms.add(new GlobalParameter("S_DOMAINNAME", S_DOMAINNAME));
		}
		sql += " order by i_order";
		List<RowBase> rows = DataUtil.getSelectRows(sql, parms);
		// List<HashMap<String, HashMap<String,String>>> allData = new
		// ArrayList<>();
		List<JSONObject> allData = new ArrayList<>();
		if (rows != null && rows.size() >= 0) {
			for (int i = 0; i < rows.size(); i++) {
				// HashMap<String,HashMap<String,String>> temp=new
				// HashMap<String,HashMap<String,String>>();
				// HashMap<String,Object> temp=new HashMap<String,Object>();
				JSONObject temp = new JSONObject();
				HashMap<String, String> map = new HashMap<String, String>();
				HashMap<String, Object> dmoin = rows.get(i);
				String str = dmoin.get("S_DOMAINNAME").toString();
				for (int j = 0; j < dmoin.size(); j++) {
					// for(int j=0;j<rows.size();j++){
					HashMap<String, Object> dmoinc = rows.get(j);
					if (dmoinc.get("S_DOMAINNAME").toString().equals(str)) {
						map.put(dmoinc.get("S_DOMAINCODE").toString(), dmoinc.get("S_DOMAINCAPTION").toString());
						temp.put(dmoinc.get("S_DOMAINNAME").toString(), map);
					}
				}
				allData.add(temp);
			}
			String result = JSONUtils.toJSONString(allData);
			return result;
		} else {
			return "";
		}
	}

	/**
	 * 根据id获取字典项
	 * 
	 * @param S_DOMAINNAME
	 * @return
	 */
	@RequestMapping("/getdomainByID")
	@ResponseBody
	public String getdomainByID(String S_DOMAINNAME) {
		String sql = "select S_DOMAINCODE,S_DOMAINNAME,s_domaincaption,PY_PREFIX,s_id,s_pid ,TYPE from DATA_DEFULATDOMAIN where 1=1 ";// and
																																		// s_ischild='1'
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		if (S_DOMAINNAME != null && !S_DOMAINNAME.equals("")) {
			sql += " and S_DOMAINNAME =@S_DOMAINNAME";
			parms.add(new GlobalParameter("S_DOMAINNAME", S_DOMAINNAME));
		}
		sql += " order by i_order";
		List<RowBase> rows = DataUtil.getSelectRows(sql, parms);
		if (rows != null && rows.size() >= 0) {
			return JSONUtils.toJSONString(rows);
		} else {
			return "";
		}
	}

	/**
	 * 获取所有运维类型(包括污水厂、供水、地表水、工业污染)
	 * 
	 * @param userID
	 * @param type
	 * @return
	 */
	@RequestMapping("/getAllTaskType")
	@ResponseBody
	public String getAllTaskType(String userID, String type, String groupID) {
		checkToken(token);
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		String sql = "";
		if (groupID != null && !groupID.equals("")) {
			sql = "select count(t.exp_no) as allnum,'0' as station_category,'污水处理厂' as name　from (select t1.exp_no from BC_ENTERPRISE_ATTR t1 left join BC_SITE_INFO t2 on t2.wwtp_id=t1.exp_no " + " left join OPERATION_GROUP_STATION_ASSO t3 on t2.exp_no=t3.station_id left join OC_GROUP t4 on t3.operation_group_id=t4.guid  where  t2.station_category='0' and t2.BUILD_STATUS='0' and t4.guid='" + groupID + "' group by t1.exp_no)t union all " + " select count(t.exp_no) as allnum,'1' as station_category,'地表水' as name　" + " from (select t1.exp_no from  monitor_station t1  " + "left join OPERATION_GROUP_STATION_ASSO t3 on t1.exp_no=t3.station_id " + "left join OC_GROUP t4 on t3.operation_group_id=t4.guid  " + "where t1.station_category='1' and t1.BUILD_STATUS='0' and t4.guid='" + groupID + "' group by t1.exp_no)t union all " + " select count(t.exp_no) as allnum,'2' as station_category,'工业污染' as name　" + "from (select t1.exp_no from  monitor_station t1  " + "left join OPERATION_GROUP_STATION_ASSO t3 on t1.exp_no=t3.station_id " + "left join OC_GROUP t4 on t3.operation_group_id=t4.guid  " + "where t1.station_category='2' and t1.BUILD_STATUS='0' and t4.guid='" + groupID + "' group by t1.exp_no)t union all " + " select count(t.exp_no) as allnum,'3' as station_category,'供水' as name　" + "from (select t1.exp_no from  monitor_station t1  " + "left join OPERATION_GROUP_STATION_ASSO t3 on t1.exp_no=t3.station_id " + "left join OC_GROUP t4 on t3.operation_group_id=t4.guid  " + "where t1.station_category='3' and t1.BUILD_STATUS='0' and t4.guid='" + groupID + "' group by t1.exp_no)t  ";

			/*
			 * +
			 * " select count(t1.exp_no) as allnum,'1' as station_category,'地表水' as name from BC_SITE_INFO t1 where t1.station_category='1' and t1.BUILD_STATUS='0' union all"
			 * +
			 * " select count(t1.exp_no) as allnum,'2' as station_category,'工业污染' as name from BC_SITE_INFO t1 where t1.station_category='2' union all"
			 * +
			 * " select count(t1.exp_no) as allnum,'3' as station_category,'供水' as name from BC_SITE_INFO t1 where t1.station_category='3' "
			 * ;
			 */
		} else {
			sql = "select count(t1.exp_no) as allnum,'0' as station_category,'污水处理厂' as name　from BC_ENTERPRISE_ATTR t1  where t1.poll_type='0'  union all" + " select count(t1.exp_no) as allnum,'1' as station_category,'地表水' as name from BC_SITE_INFO t1 where t1.station_category='1' and t1.BUILD_STATUS='0' union all" + " select count(t1.exp_no) as allnum,'2' as station_category,'工业污染' as name from BC_SITE_INFO t1 where t1.station_category='2' union all" + " select count(t1.exp_no) as allnum,'3' as station_category,'供水' as name from BC_SITE_INFO t1 where t1.station_category='3' and t1.build_status = '0' ";
		}

		/*
		 * if (userID != null && !userID.equals("")) { sql+=
		 * " and t6.c_username =@userID"; parms.add(new
		 * GlobalParameter("userID",userID) ); } if(type != null &&
		 * !type.equals("")){ //角色类型 }
		 */
		List<RowBase> rows = DataUtil.getSelectRows(sql, parms);
		if (rows != null && rows.size() >= 0) {
			return JSONUtils.toJSONString(rows);
		} else {
			return "";
		}
	}

	/**
	 * 根据事件Id获取地表水所有任务 因为时间关系 直接套用原来污水的东西
	 * 
	 * @param jobId
	 * @return
	 */
	@RequestMapping("/getSurfaceTaskStatusById")
	@ResponseBody
	public String getSurfaceTaskStatusById(String jobId, String station_id, String task_type) {
		checkToken(token);
		String result = "";
		if (task_type.equals("0")) {
			List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
			// 所有任务语句
			String ProcessedSql = "select t1.task_code,t1.task_status,t3.name as station_name,t1.job_id,t3.name as name," + " to_char(t1.start_time,'yyyy-mm-dd hh24:mi:ss') as start_time," + " to_char(t1.end_time,'yyyy-mm-dd hh24:mi:ss') as end_time ,null as TASK_TOLERANCE, " + " to_char(t1.FINISH_TIME,'yyyy-mm-dd hh24:mi:ss') as FINISH_TIME,t1.STATION_ID as exp_no from  OPERATION_TASK t1 " + " left join OPERATION_GROUP_STATION_ASSO t2 on t1.WWTP_ID =t2.station_id" + " left join BC_SITE_INFO t3 on t3.EXP_NO = t1.station_id where 1 = 1 ";
			if (jobId != null && !jobId.equals("")) {
				ProcessedSql += " and t1.JOB_ID =@jobId";
				parms.add(new GlobalParameter("jobId", jobId));
			}
			if (station_id != null && !station_id.equals("")) {
				ProcessedSql += " and t1.station_id  =@station_id";
				parms.add(new GlobalParameter("station_id", station_id));
			}
			ProcessedSql += " order by t1.FINISH_TIME desc";
			List<RowBase> rowProcessed = DataUtil.getSelectRows(ProcessedSql, parms);
			JSONArray ProcessedData = new JSONArray();
			JSONArray PendingData = new JSONArray();
			JSONArray TimeoutHandlingData = new JSONArray();
			if (rowProcessed != null && rowProcessed.size() > 0) {
				for (int i = 0; i < rowProcessed.size(); i++) {
					HashMap<String, Object> d = rowProcessed.get(i);
					String task_status = d.get("TASK_STATUS").toString();
					Calendar deathCal = Calendar.getInstance();
					SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
					String et = d.get("END_TIME").toString();// 截止时间
					// String st=d.get("START_TIME").toString();//开始时间
					Date et_date = new Date();
					// Date st_date=new Date();
					Date fishtime_date = new Date();
					Date nowdate = new Date();
					try {
						et_date = sdf.parse(et);
						// st_date=sdf.parse(st);
						deathCal.setTime(et_date);
					} catch (ParseException e) {

						e.printStackTrace();
					}
					int timeCycleNum = 0;
					if (null != d.get("TASK_TOLERANCE")) {
						timeCycleNum = Integer.parseInt(d.get("TASK_TOLERANCE").toString().replaceAll("[a-zA-Z]", ""));
						if (d.get("TASK_TOLERANCE").toString().indexOf("D") > 0) {
							deathCal.add(Calendar.DAY_OF_MONTH, timeCycleNum);
						} else if (d.get("TASK_TOLERANCE").toString().indexOf("M") > 0) {
							deathCal.add(Calendar.MONTH, timeCycleNum);
						}
					}

					Date truefishtime = deathCal.getTime();

					if (task_status.equals("0")) {// 未处理
						// if (truefishtime.getTime() >= nowdate.getTime()) {
						PendingData.add(d);
						// } else {
						// TimeoutHandlingData.add(d);
						// }
					}
					if (task_status.equals("1")) {// 已处理
						String fishtime = d.get("FINISH_TIME").toString();// 完成时间
						try {
							fishtime_date = sdf.parse(fishtime);
						} catch (ParseException e) {

							e.printStackTrace();
						}
						ProcessedData.add(d);
						// 暂时屏蔽，不做超时判断
						/*
						 * if(fishtime_date.getTime()>=truefishtime.getTime()){
						 * ProcessedData.add(d); } else{
						 * TimeoutHandlingData.add(d); }
						 */
					}
				}
			}

			JSONObject jsobj = new JSONObject();
			jsobj.put("PendingData", PendingData);
			jsobj.put("ProcessedData", ProcessedData);
			jsobj.put("TimeoutHandlingData", TimeoutHandlingData);
			List<JSONObject> allData = new ArrayList<>();
			allData.add(jsobj);
			String result1 = JSONUtils.toJSONString(allData);
			return JSONUtils.toJSONString(result1);
		}
		if (task_type.equals("1")) {
			result = getAbnormalDisposalData(jobId, station_id, "");
		}
		return result;

	}

	/**
	 * 根据事件Id获取所有任务
	 * 
	 * @param jobId
	 * @return
	 */
	@RequestMapping("/getTaskStatusById")
	@ResponseBody
	public String getTaskStatusById(String jobId, String station_id, String flowType, String task_type) {
		checkToken(token);
		String result = "";
		if (task_type.equals("0")) {
			result = getTaskStatusData(jobId, station_id, flowType);
		}
		if (task_type.equals("1")) {
			result = getAbnormalDisposalData(jobId, station_id, flowType);
		}
		return result;
	}

	/**
	 * 获取待办污水厂运营任务
	 * 
	 * @param jobId
	 * @param station_id
	 * @param flowType
	 * @return
	 */
	private String getTaskStatusData(String jobId, String station_id, String flowType) {
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		// 所有任务语句
		String ProcessedSql = "select t7.task_code,t7.task_status,t2.name as station_name,t7.job_id, t1.name,to_char(t7.start_time,'yyyy-mm-dd hh24:mi:ss') as start_time ,to_char(t7.end_time,'yyyy-mm-dd hh24:mi:ss') as end_time,t8.TASK_TOLERANCE ," + " to_char(t7.FINISH_TIME,'yyyy-mm-dd hh24:mi:ss') as FINISH_TIME,t1.exp_no\n" + " from BC_ENTERPRISE_ATTR t1\n" + " left join BC_SITE_INFO t2 on t1.exp_no = t2.wwtp_id\n" + " left join OPERATION_GROUP_STATION_ASSO t3 on t2.exp_no =\n" + "  t3.station_id";
		// 只显示当月的数据
		ProcessedSql += " left join (select * from OP_TASK t where  t.create_time >= trunc(sysdate ,'MM') AND t.create_time <= last_day(sysdate)) t7 on t3.station_id = t7.station_id";
		// ProcessedSql += " left join (select * from OP_TASK t) t7 on
		// t3.station_id = t7.station_id";
		// 任务配置表
		ProcessedSql += " left join OC_TASK_CONFIG t8 on t7.station_id = t8.station_id where 1 = 1";

		if (jobId != null && !jobId.equals("")) {
			ProcessedSql += " and t7.JOB_ID =@jobId";
			ProcessedSql += " and t8.JOB_ID =@jobId";
			parms.add(new GlobalParameter("jobId", jobId));
		}
		if (station_id != null && !station_id.equals("")) {
			ProcessedSql += " and t7.station_id =@station_id";
			ProcessedSql += " and t8.station_id =@station_id";
			parms.add(new GlobalParameter("station_id", station_id));
		}
		List<RowBase> rowProcessed = DataUtil.getSelectRows(ProcessedSql, parms);
		JSONArray ProcessedData = new JSONArray();
		JSONArray PendingData = new JSONArray();
		JSONArray TimeoutHandlingData = new JSONArray();
		if (rowProcessed != null && rowProcessed.size() > 0) {
			for (int i = 0; i < rowProcessed.size(); i++) {
				HashMap<String, Object> d = rowProcessed.get(i);
				String task_status = d.get("TASK_STATUS").toString();
				Calendar deathCal = Calendar.getInstance();
				SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
				String et = d.get("END_TIME").toString();// 截止时间
				// String st=d.get("START_TIME").toString();//开始时间
				Date et_date = new Date();
				// Date st_date=new Date();
				Date fishtime_date = new Date();
				Date nowdate = new Date();
				try {
					et_date = sdf.parse(et);
					// st_date=sdf.parse(st);
					deathCal.setTime(et_date);
				} catch (ParseException e) {

					e.printStackTrace();
				}
				int timeCycleNum = Integer.parseInt(d.get("TASK_TOLERANCE").toString().replaceAll("[a-zA-Z]", ""));
				if (d.get("TASK_TOLERANCE").toString().indexOf("D") > 0) {
					deathCal.add(Calendar.DAY_OF_MONTH, timeCycleNum);
				} else if (d.get("TASK_TOLERANCE").toString().indexOf("M") > 0) {
					deathCal.add(Calendar.MONTH, timeCycleNum);
				}
				Date truefishtime = deathCal.getTime();

				if (task_status.equals("0")) {// 未处理
					// if (truefishtime.getTime() >= nowdate.getTime()) {
					PendingData.add(d);
					// } else {
					// TimeoutHandlingData.add(d);
					// }
				}
				if (task_status.equals("1")) {// 已处理
					String fishtime = d.get("FINISH_TIME").toString();// 完成时间
					try {
						fishtime_date = sdf.parse(fishtime);
					} catch (ParseException e) {

						e.printStackTrace();
					}
					ProcessedData.add(d);
					// 暂时屏蔽，不做超时判断
					/*
					 * if(fishtime_date.getTime()>=truefishtime.getTime()){
					 * ProcessedData.add(d); } else{ TimeoutHandlingData.add(d);
					 * }
					 */
				}
			}
		}

		JSONObject jsobj = new JSONObject();
		jsobj.put("PendingData", PendingData);
		jsobj.put("ProcessedData", ProcessedData);
		jsobj.put("TimeoutHandlingData", TimeoutHandlingData);
		List<JSONObject> allData = new ArrayList<>();
		allData.add(jsobj);
		String result = JSONUtils.toJSONString(allData);
		return JSONUtils.toJSONString(result);
	}

	/**
	 * 获取异常处置数据
	 * 
	 * @param jobId
	 * @param station_id
	 * @param flowType
	 * @param status
	 * @return
	 */
	private String getAbnormalDisposalData(String jobId, String station_id, String flowType) {
		checkToken(token);
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		// String sql="select t1.* from OP_ALAR_INFO t1 left join
		// monitor_station t2 on t1.station_code = t2.exp_no where 1 = 1 ";

		String sql = "select * from (select t1.guid, t1.type,t1.alarm_value,t1.station_code,t1.status,'a' as fish_type,to_char((t1.createtime+1),'yyyy-mm-dd hh24:mi:ss')  " + "as END_TIME,to_char((t1.createtime),'yyyy-mm-dd hh24:mi:ss')  as START_TIME,'123456' as job_id,d1.s_domaincaption as type_desc " + "from OP_ALAR_INFO t1 " + "left join BC_SITE_INFO t2  on t1.station_code = t2.exp_no  " + "left join DATA_DEFULATDOMAIN d1 on ( d1.S_DOMAINNAME = '报警类型' AND d1.S_DOMAINCODE = t1.type )\n" + "where  t1.status = '0' and t1.is_recover='0' and t1.station_code='" + station_id + "' order by t1.start_time desc)t  \n" + "union all\n" + "select * from (select t1.guid, t1.type,t1.alarm_value,t1.station_code,t1.status,'b' as fish_type,to_char((t1.createtime+1),'yyyy-mm-dd')  as END_TIME" + ",to_char((t1.createtime),'yyyy-mm-dd')  as START_TIME,'123456' as job_id,d1.s_domaincaption as type_desc" + " from OP_ALAR_INFO t1 " + "left join BC_SITE_INFO t2  on t1.station_code = t2.exp_no" + " left join DATA_DEFULATDOMAIN d1 on ( d1.S_DOMAINNAME = '报警类型' AND d1.S_DOMAINCODE = t1.type )\n" + "left join OP_ALAR_PROC t3 on t1.guid=t3.alarm_id\n" + "where  t1.status = '1' and (t3.end_time-t1.createtime)  < 1 and t1.station_code='" + station_id + "' order by t1.start_time desc)t where rownum < 11\n" + "union all\n" + "select * from (select t1.guid, t1.type,t1.alarm_value,t1.station_code,t1.status,'c' as fish_type,to_char((t1.createtime+1),'yyyy-mm-dd')  as END_TIME,to_char((t1.createtime),'yyyy-mm-dd')  as START_TIME,'123456' as job_id,d1.s_domaincaption as type_desc from OP_ALAR_INFO t1 left join BC_SITE_INFO t2  on t1.station_code = t2.exp_no left join DATA_DEFULATDOMAIN d1 on ( d1.S_DOMAINNAME = '报警类型' AND d1.S_DOMAINCODE = t1.type )\n" + "left join OP_ALAR_PROC t3 on t1.guid=t3.alarm_id\n" + "where  t1.status = '1' and (t3.end_time-t1.createtime)  >1 and t1.station_code='" + station_id + "' order by t1.start_time desc)t ";
		/*
		 * if(station_id != null && !station_id.equals("")){ sql+=
		 * " and t1.station_code =@station_code"; parms.add(new
		 * GlobalParameter("station_code",station_id)); } if(status != null &&
		 * !status.equals("")){ sql+=" and t1.STATUS =@status"; parms.add(new
		 * GlobalParameter("status",status)); }
		 */
		List<RowBase> rows = DataUtil.getSelectRows(sql, parms);
		JSONArray ProcessedData = new JSONArray();// 正常时间已处理
		JSONArray PendingData = new JSONArray();// 待处理
		JSONArray TimeoutHandlingData = new JSONArray();// 超时已处理
		if (rows != null && rows.size() > 0) {
			for (int i = 0; i < rows.size(); i++) {
				HashMap<String, Object> d = rows.get(i);
				String FISH_TYPE = d.get("FISH_TYPE").toString();
				if (FISH_TYPE.equals("a")) {// 待处理
					PendingData.add(d);
				}
				if (FISH_TYPE.equals("b")) {// 已处理
					ProcessedData.add(d);
				}
				if (FISH_TYPE.equals("c")) {// 待处理
					TimeoutHandlingData.add(d);
				}
			}
			JSONObject jsobj = new JSONObject();
			jsobj.put("PendingData", PendingData);
			jsobj.put("ProcessedData", ProcessedData);
			jsobj.put("TimeoutHandlingData", TimeoutHandlingData);
			List<JSONObject> allData = new ArrayList<>();
			allData.add(jsobj);
			String result = JSONUtils.toJSONString(allData);
			return JSONUtils.toJSONString(result);
		} else {
			return "";
		}
	}

	/**
	 * 获取日常巡检所有值
	 * 
	 * @param task_code
	 * @param job_id
	 * @return
	 */
	@RequestMapping("/getTaskDataByTaskID")
	@ResponseBody
	public String getTaskDataByTaskID(String task_code, String job_id) {
		checkToken(token);
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		String sql = "";
		if (job_id != null && !job_id.equals("")) {
			if (job_id.equals("fa3ecf1a-4820-4f9f-b7b7-2553584ee7ba")) {// 日常巡检
				sql = "select A01,A02,A03,A04,A05,A06,B01,B02,B03,B04,B05,B06,C01,C02,C03,C04,C05,C06,C07,C08,C09,C10,C21,C22,C23,C24,C25,C31,C32,C33,C34,C35,D01,D02,D03,D04,D05,D06,D11,D12,D13,D14,D15,D16 from OP_INSP_RECORD where 1=1 ";
			}
			if (job_id.equals("0bddcd82-73ff-4ee7-85af-491108b7f374")) {// 定期维护
				sql = "select A01,A02,A03,A04,A05,A06,B01,B02,B03,B04,B05,B06,C01,C02,C03,C04,C05,C06,C07,C08,C09,C10," + "C21,C22,C23,C24,C25,C26,C31,C32,C33,C34,C35,C36,C37,C38,C41,C42,C43,C44,C45,C46,C47 from OP_MAIN_RECORD where 1=1 ";
			}
			if (job_id.equals("16fe2eed-eba1-4b1c-8ece-46a725a5797b")) {// 供水定期维护
				sql = "select A01,A02,A03,A04,A05,A06,B01,B02,B03,B04,B05,B06,C01,C02,C03,C04,C05,C06,C07,C08,C09,C10," + "C21,C22,C23,C24,C25,C26,C31,C32,C33,C34,C35,C36,C37,C38,C41,C42,C43,C44,C45,C46,C47 from OP_MAIN_RECORD where 1=1 ";
			}
			if (task_code != null && !task_code.equals("")) {
				sql += " and TASK_CODE =@task_code";
				parms.add(new GlobalParameter("task_code", task_code));
			}
		} else {
			return "{\"result\":false}";
		}
		List<RowBase> rows = DataUtil.getSelectRows(sql, parms);
		if (rows != null && rows.size() > 0) {
			RowBase row = rows.get(0);
			JSONObject json = JSONObject.fromObject(row);
			String jsonRrsult = json.toString();
			return jsonRrsult;
		} else {
			return "{\"result\":false}";
		}
	}

	/**
	 * 实时更新日常巡检每一项工作值
	 * 
	 * @param TASK_CODE
	 * @param filedName
	 * @param value
	 * @return
	 */
	@RequestMapping("/updateDailyOne")
	@ResponseBody
	public String updateDailyOne(String tableName, String row, String TASK_CODE) throws Exception {
		checkToken(token);
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		String sqldata = "select * from OP_INSP_RECORD where 1=1 and TASK_CODE='" + TASK_CODE + "'";
		List<RowBase> rows = DataUtil.getSelectRows(sqldata, parms);
		JSONObject json = JSONObject.fromObject(row);
		if (rows.size() > 0) {
			// String isnew=json.getString("FIELD_ISNEW").toString();
			json.put("FIELD_ISNEW", "flase");

		}

		tableName = tableName.toUpperCase();
		try {
			RowBase entity = JSONConvertUtils.convertToEntity(json.toString());
			Object obj = entity.getValue("_IS_DOMAIN_TRUE");
			if (obj != null && obj.toString().toLowerCase().equals("true")) {
				return null;
			} else {
				return tableSave(tableName, entity);
			}
		} catch (Exception e) {
			e.printStackTrace();
			throw e;
		}
	}

	/**
	 * 实时更新定期维护每一项工作值
	 * 
	 * @param TASK_CODE
	 * @param filedName
	 * @param value
	 * @return
	 */
	@RequestMapping("/updateMaintainanceOne")
	@ResponseBody
	public String updateMaintainanceOne(String tableName, String row, String TASK_CODE) throws Exception {
		checkToken(token);
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		String sqldata = "select * from OP_MAIN_RECORD where 1=1 and TASK_CODE='" + TASK_CODE + "'";
		List<RowBase> rows = DataUtil.getSelectRows(sqldata, parms);
		JSONObject json = JSONObject.fromObject(row);
		if (rows.size() > 0) {
			json.put("FIELD_ISNEW", "flase");

		}

		tableName = tableName.toUpperCase();
		try {
			RowBase entity = JSONConvertUtils.convertToEntity(json.toString());
			Object obj = entity.getValue("_IS_DOMAIN_TRUE");
			if (obj != null && obj.toString().toLowerCase().equals("true")) {
				return null;
			} else {
				return tableSave(tableName, entity);
			}
		} catch (Exception e) {
			e.printStackTrace();
			throw e;
		}
	}

	private String tableSave(String tableName, RowBase entity) throws Exception {
		ITableFactory tableFactory = (ITableFactory) SpringBeanFactory.getBean("TableFactory");
		ITable pTable = tableFactory.openTable(tableName);

		String returnString = FormEditInterceptorClass.BeforeDbEditOptionEx(pTable, entity, DbEditType.Insert);
		if (StringUtils.IsNullOrSpace(returnString)) {
			pTable.startEditing();
			try {
				pTable.save(entity);

				// 再做一次字典转议
				ConvertCaptionUtils.convertCaptionField(pTable, entity);
				ObjectMapper mapper = new ObjectMapper();
				String userMapJson = mapper.writeValueAsString(entity);
				pTable.stopEditing(true);

				return userMapJson;
			} catch (Exception e) {
				pTable.stopEditing(false);
				throw e;
			}
		} else {
			return returnString;
		}
	}

	/**
	 * 获取地表水站数据
	 * 
	 * @param userID
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/getSurfaceWaterData")
	@ResponseBody
	public String getSurfaceWaterData(String groupId) throws Exception {
		checkToken(token);
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		String sql = "select t1.* from BC_SITE_INFO t1 left join OPERATION_GROUP_STATION_ASSO t3 " + " on t1.exp_no =t3.station_id where  t1.station_category='1' and t1.BUILD_STATUS='0' and t1.operation_unit = '深圳市浩瑞泰科技有限公司'";
		if (null != groupId && !groupId.isEmpty()) {
			sql += " and t3.operation_group_id = @groupId ";
			parms.add(new GlobalParameter("groupId", groupId));
		}
		List<RowBase> rows = DataUtil.getSelectRows(sql, parms);
		if (rows != null && rows.size() >= 0) {
			return JSONUtils.toJSONString(rows);
		} else {
			return "";
		}
	}

	@RequestMapping("/getSbByStationID")
	@ResponseBody
	public String getSbByStationID(String monitor_point) {
		String sql = "select * from BC_SITE_DEVICE_RPT  where 1=1  ";
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		if (monitor_point != null && !monitor_point.equals("")) {
			sql += " and monitor_point =@monitor_point";
			parms.add(new GlobalParameter("monitor_point", monitor_point));
		}
		List<RowBase> rows = DataUtil.getSelectRows(sql, parms);
		if (rows != null && rows.size() >= 0) {
			return JSONUtils.toJSONString(rows);
		} else {
			return "";
		}
	}

	/**
	 * 根据站点获取在线设备
	 * 
	 * @param monitor_point
	 * @return
	 */
	@RequestMapping("/getSbByStationID1")
	@ResponseBody
	public String getSbByStationID1(String monitor_point) {
		String sql = "select * from BC_SITE_DEVICE_RPT  where 1=1  ";
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		if (monitor_point != null && !monitor_point.equals("")) {
			sql += " and monitor_point =@monitor_point";
			parms.add(new GlobalParameter("monitor_point", monitor_point));
		}
		List<RowBase> rows = DataUtil.getSelectRows(sql, parms);
		if (rows != null && rows.size() >= 0) {
			return JSONUtils.toJSONString(rows);
		} else {
			return "";
		}
	}

	/**
	 * 数据保存
	 * 
	 * @param token
	 * @param userID
	 * @param tableName
	 * @param row
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/save")
	@ResponseBody
	public String save(String token, String userID, String tableName, String row, String dataType, String TASK_CODE, String CREATE_TIME,
			String FINISH_BY) throws Exception {

		checkToken(token);

		tableName = tableName.toUpperCase();
		// if (tableName.equals("OP_ALAR_PROC")) {
		// try {
		//
		// JSONObject json = JSONObject.fromObject(row);
		// String result = json.optString("PROCESS_RESULT");
		// json.put("STATUS", result);
		// row = json.toString();
		// } catch (Exception e) {
		//
		// }
		// }
		// 设备故障及维修
		if (tableName.equals("OP_FAILURE_REPAIR") && dataType.equals("0")) {
			operationDataVaildService.IsRepair(row);
		}
		String result = null;
		try {
			RowBase entity = JSONConvertUtils.convertToEntity(row);
			Object obj = entity.getValue("_IS_DOMAIN_TRUE");
			if (obj != null && obj.toString().toLowerCase().equals("true")) {
				result = null;
			} else {
				result = tableSave(tableName, entity);
				if (!TASK_CODE.isEmpty() && !TASK_CODE.equals("")) {
					updateTaskStatus(TASK_CODE, "1", CREATE_TIME, FINISH_BY);
				}

			}
		} catch (Exception e) {
			e.printStackTrace();
			throw e;
		}
		return result;
	}

	/**
	 * 批量数据保存
	 * 
	 * @param tableName
	 *            数据表名
	 * @param rows
	 *            记录集，Json格式数组
	 */
	@RequestMapping("/saveList")
	@ResponseBody
	public String saveList(String tableName, String rows, String dataType, String TASK_CODE, String CREATE_TIME, String FINISH_BY) {
		if (StringUtils.IsNullOrSpace(tableName) || StringUtils.IsNullOrSpace(rows)) {
			return null;
		}
		tableName = tableName.toUpperCase();
		// dataType站点类型：0-污染源 1-地表水 2-工业污染源 3-供水
		// 日常巡检数据
		if (tableName.equals("OP_RECO_RPT") && dataType.equals("0")) {
			operationDataVaildService.IsInspection(rows);
		}
		// 定期维护
		if (tableName.equals("OPERATION_RECORD_MAINTAINANCE") && dataType.equals("0")) {
			operationDataVaildService.IsMaintainance(rows);
		}
		// 耗材及备件更换
		if (tableName.equals("OP_MATE_REPLACE") && dataType.equals("0")) {
			operationDataVaildService.IsReplace(rows);
		}
		// 日常校准
		if (tableName.equals("OPERATION_DAILY_VERIFICATION") && dataType.equals("0")) {
			operationDataVaildService.IsVerification(rows);
		}
		// 超标比对
		if (tableName.equals("OP_EXCEED_COMP") && dataType.equals("0")) {
			operationDataVaildService.IsComparison(rows);
		}
		// 水样比对
		if (tableName.equals("OP_SAMPLE_COMP") && dataType.equals("0")) {
			operationDataVaildService.IsSampleComparison(rows);
		}
		// 标样核查
		if (tableName.equals("OP_STAND_VERI") && dataType.equals("0")) {
			operationDataVaildService.IsStandVerification(rows);
		}
		String result = null;
		List<RowBase> rowList = new ArrayList<RowBase>();
		// 数据对象
		JSONArray jsonArray = JSONArray.fromObject(rows);
		if (jsonArray.size() > 0) {
			for (int i = 0; i < jsonArray.size(); i++) {
				JSONObject rowItem = jsonArray.getJSONObject(i);
				RowBase entity = (RowBase) JSONObject.toBean(rowItem, RowBase.class);
				if (!(rowItem.get("childValues") instanceof JSONNull)) {
					JSONObject childValuesObj = JSONObject.fromObject(rowItem.get("childValues"));
					getDataSource(childValuesObj, entity);
				}
				rowList.add(entity);
			}
		}
		ITableFactory tableFactory = (ITableFactory) SpringBeanFactory.getBean("TableFactory");
		ITable pTable = tableFactory.openTable(tableName);
		String returnString = FormEditInterceptorClass.BeforeDbEditOptionEx(pTable, rowList, DbEditType.Insert);
		if (StringUtils.IsNullOrSpace(returnString)) {
			pTable.startEditing();
			try {
				pTable.save(rowList);

				pTable.stopEditing(true);
				result = "{\"result\":true}";
				updateTaskStatus(TASK_CODE, "1", CREATE_TIME, FINISH_BY);
			} catch (Exception e) {
				pTable.stopEditing(false);
				throw e;
			}
		} else {
			result = returnString;
		}
		return result;
	}

	/**
	 * 递归取子表
	 * 
	 * @param objs
	 * @param rowBase
	 * @return
	 */
	@SuppressWarnings("unchecked")
	private RowBase getDataSource(JSONObject objs, RowBase rowBase) {
		JSONObject childValues = objs;
		Set<String> childTables = childValues.keySet();
		// 收集子表记录
		HashMap<String, List<RowBase>> childHashMap = new HashMap<String, List<RowBase>>();
		for (String chidlTable : childTables) {
			List<RowBase> childRowBases = new ArrayList<RowBase>();
			JSONArray list2 = (JSONArray) childValues.get(chidlTable);
			for (int i = 0; i < list2.size(); i++) {
				JSONObject jo = (JSONObject) list2.get(i);
				RowBase childRowBase = (RowBase) JSONObject.toBean(jo, RowBase.class);
				if (childRowBase.containsKey("childValues")) {
					childRowBase.remove("childValues");
				}

				// 递归取子表
				if (!(jo.get("childValues") instanceof JSONNull)) {
					JSONObject childValuesObj = JSONObject.fromObject(jo.get("childValues"));
					getDataSource(childValuesObj, childRowBase);
				}
				childRowBases.add(childRowBase);
			}
			childHashMap.put(chidlTable, childRowBases);
		}
		rowBase.setChildValues(childHashMap);
		return rowBase;
	}

	/**
	 * 生成任务
	 * 
	 * @param row
	 * @return
	 */
	@RequestMapping("/Generate")
	@ResponseBody
	public String Generate(String row) {
		JSONObject json = JSONObject.fromObject(row);
		String stationId = json.get("STATION_ID").toString();
		String groupId = json.get("OPERATION_GROUP_ID").toString();
		String jobId = json.get("JOB_ID").toString();
		String pcode = json.get("TASK_CODE").toString();
		SimpleDateFormat sf = new SimpleDateFormat("yyyyMMdd HH:mm:ss");
		SimpleDateFormat sfd = new SimpleDateFormat("yyyy-MM-dd");
		String dateStr = sf.format(new Date());
		String st = sfd.format(new Date());
		try {
			Object taskCountStr = DataUtil.getScale(" SELECT TASK_COUNT FROM OP_SITE_TASK_COUNT WHERE STATION_ID = '" + stationId + "' ",
					null);
			int taskCount = 0;
			if (taskCountStr != null) {
				taskCount = Integer.parseInt(taskCountStr + "");
			}
			String taskCode = dateStr + "-" + stationId + "-" + taskCount;
			json.put("TASK_CODE", taskCode);
			json.put("START_TIME", st);
			json.put("END_TIME", st);
			List<GlobalParameter> parms = new ArrayList<>();
			parms.add(new GlobalParameter("stationId", stationId));
			parms.add(new GlobalParameter("groupId", groupId));
			parms.add(new GlobalParameter("taskCode", taskCode));
			parms.add(new GlobalParameter("jobId", jobId));
			parms.add(new GlobalParameter("pcode", pcode));
			/*
			 * parms.add(new GlobalParameter("START_TIME", st)); parms.add(new
			 * GlobalParameter("END_TIME", st));
			 */
			String insertSql = " insert into operation_task (GUID, STATION_ID,OPERATION_GROUP_ID, TASK_STATUS, START_TIME, END_TIME, FINISH_TIME, FINISH_BY, CREATE_TIME, TASK_CODE, JOB_ID,PARENT_TASK_CODE) " + "values (sys_guid(), @stationId,@groupId, '0', sysdate,sysdate, null, '', sysdate, @taskCode,@jobId,@pcode)";
			DataUtil.ExecuteUpdateSql(insertSql, parms);
		} catch (Exception e) {
			throw e;
		}
		return json.toString();
		// HashMap<String, String> map=
	}

	// 删除任务
	@RequestMapping("/deleteOperationTask")
	@ResponseBody
	public String deleteOperationTask(String body) {
		JSONObject resultJson = new JSONObject();
		// code表示删除的记录数目，如果出现异常，code=-1
		String code = "0";
		// 执行中出现的异常
		String error = "";

		try {
			JSONObject paramsObject = JSONObject.fromObject(body);
			String taskCode = paramsObject.optString("taskCode");
			String groupId = paramsObject.optString("groupId");
			List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
			parms.add(new GlobalParameter("taskCode", taskCode));
			parms.add(new GlobalParameter("groupId", groupId));
			// 任务ID不能为空，否则无法删除
			String sql = null;

			if (taskCode != null && !taskCode.isEmpty()) {
				sql = "select * from OP_TASK where 1 = 1 AND TASK_CODE = @taskCode";
				// 组ID为空，暂时给予全部权限,不为空则必须判断
				if (groupId != null && !groupId.isEmpty()) {
					sql += " AND OPERATION_GROUP_ID = @groupId";
				}
				// 先查询有没有符合要求的数据
				List<RowBase> rows = DataUtil.getSelectRows(sql, parms);
				int count = 0;
				if (rows != null && rows.size() > 0) {
					count = rows.size();
					String taskStatus = rows.get(0).getSafeString("TASK_STATUS");
					if ("0".equals(taskStatus)) {
						// 复核删除条件，，删除数据
						sql = "delete from OP_TASK where TASK_STATUS = '0' AND TASK_CODE = @taskCode";
						// 组ID为空，暂时给予全部权限,不为空则必须判断
						if (groupId != null && !groupId.isEmpty()) {
							sql += " AND OPERATION_GROUP_ID = @groupId";
						}
						int deleteResult = DataUtil.ExecuteUpdateSql(sql, parms);
						if (deleteResult == 0) {
							code = "1";
						} else {
							code = "0";
						}
					} else {
						error += "已处理任务不支持删除 ";
					}
				} else {
					error += "未找到该条任务 ";
				}
			} else {
				error += "任务ID不能为空 ";
				code = "-1";
			}
		} catch (Exception e) {
			error += e.getMessage() + " ";
		}
		if (!error.isEmpty()) {
			error = "删除失败," + error;
		}
		resultJson.put("code", code);
		resultJson.put("error", error);
		return resultJson.toString();
	}

	/**
	 * 更新报警信息表
	 * 
	 * @param guid
	 * @param TASK_STATUS
	 * @return
	 */
	@RequestMapping("/updateALARMStatus")
	@ResponseBody
	public String updateALARMStatus(String guid, String RECEIVED_BY, String IS_RECOVER) {
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");// 设置日期格式
		// new Date()为获取当前系统时间
		String date = df.format(new Date());
		String sql = "update  OP_ALAR_INFO set STATUS='1', RECEIVED_BY='" + RECEIVED_BY + "',IS_RECOVER = '" + IS_RECOVER + "',UPDATETIME = to_date('" + date + "','yyyy-mm-dd HH24:mi:ss')" + "  where GUID='" + guid + "'";
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		int i = DataUtil.ExecuteUpdateSql(sql, parms);
		if (i == 0) {
			return "{\"result\":true}";
		} else {
			return "{\"result\":false}";
		}

	}

	/**
	 * 获取签到次数
	 * 
	 * @param GROUP_ID
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/getRegistrationCount")
	@ResponseBody
	public String getRegistrationCount(String GROUP_ID, String WTTP_ID) throws Exception {
		String sql = "select count(*) as sum from OP_REGI_INFO  where 1=1  ";
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		if (GROUP_ID != null && !GROUP_ID.equals("")) {
			sql += " and GROUP_ID =@GROUP_ID";
			parms.add(new GlobalParameter("GROUP_ID", GROUP_ID));
		}
		if (WTTP_ID != null && !WTTP_ID.equals("")) {
			sql += " and WTTP_ID =@WTTP_ID ";
			parms.add(new GlobalParameter("WTTP_ID", WTTP_ID));
		}
		sql += " and to_date(to_char(time,'yyyy-mm'),'yyyy-mm') >to_date(to_char(add_months(trunc(sysdate),-1),'yyyy-mm'),'yyyy-mm')";
		List<RowBase> rows = DataUtil.getSelectRows(sql, parms);
		JSONObject jo = new JSONObject();
		if (rows != null && rows.size() >= 0) {
			jo.put("SUM", rows.get(0).getValue("SUM").toString());
			return JSONUtils.toJSONString(jo);
		} else {
			return "";
		}
	}

	/**
	 * 获取污水厂范围坐标
	 * 
	 * @param exp_no
	 * @return
	 */
	@RequestMapping("/getXY")
	@ResponseBody
	public String getXY(String STATION_CODE) {
		// String sql = "select * from ps_wwtp_xy where 1=1 ";
		// List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		// if (exp_no != null && !exp_no.equals("")) {
		// sql += " and exp_no =@exp_no";
		// parms.add(new GlobalParameter("exp_no", exp_no));
		// }
		// List<RowBase> rows = DataUtil.getSelectRows(sql, parms);
		// if (rows != null && rows.size() >= 0) {
		// return JSONUtils.toJSONString(rows);
		// } else {
		// return "";
		// }
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		String sql = "select * from STATION_INFO where 1=1 ";
		if (null != STATION_CODE) {
			sql += " and STATION_CODE = @STATION_CODE";
			parms.add(new GlobalParameter("STATION_CODE", STATION_CODE));
		}
		List<RowBase> rows = DataUtil.getSelectRows(sql, parms);
		if (rows != null && rows.size() >= 0) {
			return JSONUtils.toJSONString(rows);
		} else {
			return "";
		}

	}

	/**
	 * 获取运维组人员信息
	 * 
	 * @param exp_no
	 * @return
	 */
	@RequestMapping("/getGroupUser")
	@ResponseBody
	public String getGroupUser(String exp_no) {
		String sql = "select t3.group_name, t3.guid, t1.s_userid, t1.c_userealname\n" + "  from safe_user t1\n" + "  left join OC_GROUP_ASSO t2 on t1.s_userid = t2.user_id\n" + "  left join OC_GROUP t3 on t2.group_id = t3.guid\n" + " left join operation_group_station_asso t4 on t3.guid=t4.operation_group_id " + " where group_name is not null";
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		if (exp_no != null && !exp_no.equals("")) {
			sql += " and t4.station_id =@exp_no";
			parms.add(new GlobalParameter("exp_no", exp_no));
		}
		List<RowBase> rows = DataUtil.getSelectRows(sql, parms);
		if (rows != null && rows.size() >= 0) {
			return JSONUtils.toJSONString(rows);
		} else {
			return "";
		}
	}

	@Autowired
	DomainService domainService;

	/**
	 * 获取日常巡检运维项
	 * 
	 * @param resq
	 * @param res
	 * @throws Exception
	 */
	@RequestMapping(value = "/getInspectionItems")
	@ResponseBody
	public String getInspectionItems(HttpServletRequest resq, HttpServletResponse res) throws Exception {
		String result = domainService.getDailyInspectionItems();
		return (result);
	}

	/**
	 * 获取定期维护运维项
	 * 
	 * @param resq
	 * @param res
	 * @throws Exception
	 */
	@RequestMapping(value = "/getMaintainanceItems")
	@ResponseBody
	public String getMaintainanceItems(HttpServletRequest resq, HttpServletResponse res) throws Exception {
		String result = domainService.getPeriodMaintainanceItems();
		return (result);
	}

	/**
	 * 根据站点获取在线设备
	 * 
	 * @param flow_type
	 * @param wwtp_id
	 * @return
	 */
	@RequestMapping("/getEquipmentByStation")
	@ResponseBody
	public String getEquipmentByStation(String flow_type, String wwtp_id) {
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		String sql = "select t1.name,t1.DEVICE_TYPENUM,t1.DEVICE_NUM from BC_SITE_DEVICE_RPT t1 " + "left join BC_SITE_INFO t2 on t1.monitor_point=t2.exp_no where 1=1 ";
		if (flow_type != null && !flow_type.equals("")) {
			sql += " and t2.flow_type =@flow_type";
			parms.add(new GlobalParameter("flow_type", flow_type));
		}
		if (wwtp_id != null && !wwtp_id.equals("")) {
			sql += " and t2.wwtp_id =@wwtp_id";
			parms.add(new GlobalParameter("wwtp_id", wwtp_id));
		}
		List<RowBase> rows = DataUtil.getSelectRows(sql, parms);
		if (rows != null && rows.size() >= 0) {
			return JSONUtils.toJSONString(rows);
		} else {
			return "";
		}
	}

	/**
	 * 根据站点获取在线设备
	 * 
	 * @param flow_type
	 * @param wwtp_id
	 * @return
	 */
	@RequestMapping("/getEquipmentByStation1")
	@ResponseBody
	public String getEquipmentByStation1(String stationId) {
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		String sql = "select t.name,t1.S_DOMAINCAPTION,t.DEVICE_TYPENUM,t.DEVICE_NUM,t.monitor_pollutants " + "from BC_SITE_DEVICE_RPT t left join (select t.S_DOMAINCODE,t.S_DOMAINCAPTION  " + "from data_defulatdomain  t  where t.S_DOMAINNAME='MONITOR_PARAM')t1 " + "on t1.S_DOMAINCODE = t.monitor_pollutants where 1=1";
		if (stationId != null && !stationId.equals("")) {
			sql += " and t.monitor_point =@wwtp_id";
			parms.add(new GlobalParameter("wwtp_id", stationId));
		}
		List<RowBase> rows = DataUtil.getSelectRows(sql, parms);
		if (rows != null && rows.size() >= 0) {
			return JSONUtils.toJSONString(rows);
		} else {
			return "";
		}
	}

	/**
	 * 根据站点获取供水在线设备
	 * 
	 * @param flow_type
	 * @param wwtp_id
	 * @return
	 */
	@RequestMapping("/getGSEquipmentByStation")
	@ResponseBody
	public String getGSEquipmentByStation(String EXP_NO) {
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		String sql = "select t3.S_DOMAINCAPTION,t1.guid,t1.name,t1.DEVICE_TYPENUM,t1.DEVICE_NUM," + "t1.MONITOR_POLLUTANTS ,t4.DENSITY_ALARM_DOWMLIMIT,t4.DENSITY_ALARM_UPLIMIT," + "t4.ABNORMAL_MIN,t4.ABNORMAL_MAX  from BC_SITE_DEVICE_RPT t1 " + "left join BC_SITE_INFO t2 on t1.monitor_point=t2.exp_no " + "left join (select t.S_DOMAINCODE,t.S_DOMAINCAPTION  from data_defulatdomain  " + "t  where t.S_DOMAINNAME='MONITOR_PARAM') t3 on t3.s_domaincode = t1.MONITOR_POLLUTANTS  " + "left join BC_SITE_POLL  t4 on t4.site_id = t1.monitor_point " + "and t4.name = t1.MONITOR_POLLUTANTS where 1=1 ";
		if (EXP_NO != null && !EXP_NO.equals("")) {
			sql += " and t2.EXP_NO =@EXP_NO";
			parms.add(new GlobalParameter("EXP_NO", EXP_NO));
		}
		List<RowBase> rows = DataUtil.getSelectRows(sql, parms);
		if (rows != null && rows.size() >= 0) {
			return JSONUtils.toJSONString(rows);
		} else {
			return "";
		}
	}

	/**
	 * 根据站点获取数据比对污染物参数
	 * 
	 * @param flow_type
	 * @param wwtp_id
	 * @return
	 */
	@RequestMapping("/getGSSJBDByStation")
	@ResponseBody
	public String getGSSJBDByStation(String EXP_NO) {
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		String sql = "SELECT t1.s_domaincaption,t1.s_domaincode from BC_SITE_POLL t left join " + " data_defulatdomain  t1 on t.name = t1.S_DOMAINCODE  where t1.s_domainname = '深圳供水参数'  ";
		if (EXP_NO != null && !EXP_NO.equals("")) {
			sql += " and t.SITE_ID =@EXP_NO";
			parms.add(new GlobalParameter("EXP_NO", EXP_NO));
		}
		List<RowBase> rows = DataUtil.getSelectRows(sql, parms);
		if (rows != null && rows.size() >= 0) {
			return JSONUtils.toJSONString(rows);
		} else {
			return "";
		}
	}

	/**
	 * 获取供水数据比对详情数据
	 * 
	 * @param flow_type
	 * @param wwtp_id
	 * @return
	 */
	@RequestMapping("/getGSSJBDDetailData")
	@ResponseBody
	public String getGSSJBDDetailData(String task_code) {
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		String sql = "select t1.s_domaincaption,t1.s_domaincaption,t.guid,t.task_code,to_char(t.tm,'yyyy-mm-dd')as tm," + "t.measured_value,t.gbmethod_value from DATA_COMPARISON t left join " + "(select t.S_DOMAINCODE,t.S_DOMAINCAPTION  from data_defulatdomain  t  " + "where S_DOMAINNAME='MONITOR_PARAM') t1 on t.iterm_param = t1.S_DOMAINCODE where 1=1 ";
		if (!task_code.isEmpty()) {
			sql += " and t.task_code =@task_code";
			parms.add(new GlobalParameter("task_code", task_code));
		}
		List<RowBase> rows = DataUtil.getSelectRows(sql, parms);
		if (rows != null && rows.size() >= 0) {
			return JSONUtils.toJSONString(rows);
		} else {
			return "";
		}
	}

	/**
	 * 更新供水数据比对详情数据
	 * 
	 * @param flow_type
	 * @param wwtp_id
	 * @return
	 */
	@RequestMapping("/updateGSSJBDDetailData")
	@ResponseBody
	public String updateGSSJBDDetailData(String GUID, String online, String def) {
		if (GUID.isEmpty() || online.isEmpty() || def.isEmpty()) {
			return "{\"result\":false}";
		}
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		String sql = "update  DATA_COMPARISON set MEASURED_VALUE = @MEASURED_VALUE,GBMETHOD_VALUE = @GBMETHOD_VALUE where GUID =@GUID";
		parms.add(new GlobalParameter("GUID", GUID));
		parms.add(new GlobalParameter("MEASURED_VALUE", online));
		parms.add(new GlobalParameter("GBMETHOD_VALUE", def));

		int i = DataUtil.ExecuteUpdateSql(sql, parms);
		if (i == 0) {
			return "{\"result\":true}";
		} else {
			return "{\"result\":false}";
		}
	}

	/**
	 * 获取供水备件耗材更换详情数据
	 * 
	 * @param flow_type
	 * @param wwtp_id
	 * @return
	 */
	@RequestMapping("/getGSBJHCGHDetailData")
	@ResponseBody
	public String getSBHCGHDetailData(String task_code) {
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		String sql = "select t1.s_domaincaption,t.guid,t.task_id,t.material_type,t.material_quantity," + "to_char(t.replace_date,'yyyy-mm-dd,hh24:mi:ss')as replace_date,t.replace_result,t.material_unit from OP_MATE_REPLACE t " + "left join (select t.S_DOMAINCODE,t.S_DOMAINCAPTION  from data_defulatdomain  t  " + "where S_DOMAINNAME='供水耗材名称') t1 on t.material_type = t1.s_domaincode where 1=1";
		if (!task_code.isEmpty()) {
			sql += " and t.task_id =@task_code";
			parms.add(new GlobalParameter("task_code", task_code));
		}
		List<RowBase> rows = DataUtil.getSelectRows(sql, parms);
		if (rows != null && rows.size() >= 0) {
			return JSONUtils.toJSONString(rows);
		} else {
			return "";
		}
	}

	/**
	 * 更新供水备件耗材更换详情数据
	 * 
	 * @param flow_type
	 * @param wwtp_id
	 * @return
	 */
	@RequestMapping("/updateGSBJHCGHDetailData")
	@ResponseBody
	public String updateGSBJHCGHDetailData(String GUID, String upnum, String upunit, String status) {
		if (GUID.isEmpty() || upnum.isEmpty() || upunit.isEmpty()) {
			return "{\"result\":false}";
		}
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		String sql = "update  OP_MATE_REPLACE set material_quantity = @material_quantity,material_unit = @material_unit,replace_result = @replace_result where GUID =@GUID";
		parms.add(new GlobalParameter("GUID", GUID));
		parms.add(new GlobalParameter("material_quantity", upnum));
		parms.add(new GlobalParameter("material_unit", upunit));
		parms.add(new GlobalParameter("replace_result", status));

		int i = DataUtil.ExecuteUpdateSql(sql, parms);
		if (i == 0) {
			return "{\"result\":true}";
		} else {
			return "{\"result\":false}";
		}
	}

	/**
	 * 获取供水异常处理详情数据
	 * 
	 * @param flow_type
	 * @param wwtp_id
	 * @return
	 */
	@RequestMapping("/getGSYCCLDetailData")
	@ResponseBody
	public String getGSYCCLDetailData(String task_code) {
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		String sql = "select t1.s_domaincaption,t.guid,t.status,t.exception_reason,t.process_result,t.faultcause,t.exception_process," + "to_char(t.start_time,'yyyy-mm-dd,hh24:mi:ss')as start_time," + "to_char(t.end_time,'yyyy-mm-dd,hh24:mi:ss')as end_time," + "to_char(t.restore_time,'yyyy-mm-dd,hh24:mi:ss')as restore_time " + "from OP_ALAR_PROC t " + "left join (select t.s_domaincode,t.s_domaincaption from data_defulatdomain t " + "where t.s_domainname='供水异常故障项') t1 on t.exception_reason = t1.s_domaincode where 1=1";
		if (!task_code.isEmpty()) {
			sql += " and t.task_code =@task_code";
			parms.add(new GlobalParameter("task_code", task_code));
		}
		List<RowBase> rows = DataUtil.getSelectRows(sql, parms);
		if (rows != null && rows.size() >= 0) {
			return JSONUtils.toJSONString(rows);
		} else {
			return "";
		}
	}

	/**
	 * 更新供水异常处理详情数据
	 * 
	 * @param flow_type
	 * @param wwtp_id
	 * @return
	 */
	@RequestMapping("/updateGSYCCLDetailData")
	@ResponseBody
	public String updateGSYCCLDetailData(String GUID, String EXCEPTION_REASON, String process, String reason, String EQUIPMENT_NO) {
		if (GUID.isEmpty() || EXCEPTION_REASON.isEmpty() || process.isEmpty()) {
			return "{\"result\":false}";
		}
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		String sql = "update  OP_ALAR_PROC set EXCEPTION_REASON = @EXCEPTION_REASON,EXCEPTION_PROCESS = @EXCEPTION_PROCESS,FAULTCAUSE = @FAULTCAUSE,EQUIPMENT_NO = @EQUIPMENT_NO where GUID =@GUID";
		parms.add(new GlobalParameter("GUID", GUID));
		parms.add(new GlobalParameter("EXCEPTION_REASON", EXCEPTION_REASON));
		parms.add(new GlobalParameter("EXCEPTION_PROCESS", process));
		parms.add(new GlobalParameter("FAULTCAUSE", reason));
		parms.add(new GlobalParameter("EQUIPMENT_NO", EQUIPMENT_NO));
		int i = DataUtil.ExecuteUpdateSql(sql, parms);
		if (i == 0) {
			return "{\"result\":true}";
		} else {
			return "{\"result\":false}";
		}
	}

	/**
	 * 根据站点获取供水异常参数名称
	 * 
	 * @param flow_type
	 * @param wwtp_id
	 * @return
	 */
	@RequestMapping("/getGsAbnormal")
	@ResponseBody
	public String getGsAbnormal() {
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		String sql = "select t.s_domaincode,t.s_domaincaption from data_defulatdomain t where t.s_domainname='供水异常故障项'";
		List<RowBase> rows = DataUtil.getSelectRows(sql, parms);
		if (rows != null && rows.size() >= 0) {
			return JSONUtils.toJSONString(rows);
		} else {
			return "";
		}
	}

	/**
	 * 获取供水站数据
	 * 
	 * @param userID
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/getWaterSupplyrData")
	@ResponseBody
	public String getWaterSupplyrData(String userID, String groupId, String scId) throws Exception {
		checkToken(token);
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		String sql = "";
		if (groupId != null && !groupId.equals("")) {
			sql = "select sum(t.sum) as sum, t.name, t.exp_no\n" + "  from (select t1.name,t1.exp_no,(case t4.task_status when '0' then 1  else 0 end) as sum,t4.task_status,t1.wwtp_id from BC_SITE_INFO t1\n" + "  left join OPERATION_GROUP_STATION_ASSO t2 on t1.exp_no=t2.station_id\n" + "  left join OC_GROUP t3 on t2.operation_group_id=t3.guid\n" + "  left join OPERATION_TASK t4 on t1.exp_no=t4.station_id\n" + "  where t1.station_category='3' and t1.BUILD_STATUS='0'\n" + "  and t2.OPERATION_GROUP_ID='" + groupId + "') t ";
		} else {
			sql = "select sum(t.sum) as sum, t.name, t.exp_no\n" + "  from (select t1.name,t1.exp_no,(case t4.task_status when '0' then 1  else 0 end) as sum,t4.task_status,t1.wwtp_id from BC_SITE_INFO t1\n" + "  left join OPERATION_GROUP_STATION_ASSO t2 on t1.exp_no=t2.station_id\n" + "  left join OC_GROUP t3 on t2.operation_group_id=t3.guid\n" + "  left join OPERATION_TASK t4 on t1.exp_no=t4.station_id\n" + "  where t1.station_category='3' and t1.BUILD_STATUS='0'\n" + "  ) t  ";
		}
		if (!scId.isEmpty()) {
			sql += " where WWTP_ID = @scId ";
			parms.add(new GlobalParameter("scId", scId));
		}
		sql += "group by t.name, t.exp_no,t.wwtp_id";
		List<RowBase> rows = DataUtil.getSelectRows(sql, parms);
		if (rows != null && rows.size() >= 0) {
			return JSONUtils.toJSONString(rows);
		} else {
			return "";
		}
	}

	/**
	 * 根据站点id获取供水任务数据
	 * 
	 * @param station_id
	 * @return
	 */
	@RequestMapping("/getWaterSupplyTaskDataByID")
	@ResponseBody
	public String getWaterSupplyTaskDataByID(String station_id) {
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		String sql = "select t2.job_name,t1.task_code,t1.station_id,t3.flow_type,t2.guid as job_id from OP_TASK t1 " + "left join operation_job t2 on t2.guid=t1.job_id " + "left join  monitor_station t3 on t3.exp_no=t1.station_id where 1=1 and t1.task_status='0' ";
		if (station_id != null && !station_id.equals("")) {
			sql += " and t3.exp_no =@station_id";
			parms.add(new GlobalParameter("station_id", station_id));

		}
		List<RowBase> rows = DataUtil.getSelectRows(sql, parms);
		if (rows != null && rows.size() >= 0) {
			return JSONUtils.toJSONString(rows);
		} else {
			return "";
		}
	}

	/**
	 * 获取未处理、已处理供水数据
	 * 
	 * @param jobId
	 * @param station_id
	 * @return
	 */
	@RequestMapping("/getWaterSupplyJobData")
	@ResponseBody
	private String getWaterSupplyJobData(String jobId, String station_id) {
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		// 所有任务语句
		String ProcessedSql = "select t.task_code ,t.job_id,t.task_status,t2.name,to_char(t.start_time, 'yyyy-mm-dd') as start_time," + " to_char(t.end_time, 'yyyy-mm-dd hh24:mi:ss') as end_time,to_char(t.FINISH_TIME, 'yyyy-mm-dd') " + " as FINISH_TIME ,t2.exp_no from OP_TASK t " + " left join BC_SITE_INFO t2 on t.station_id = t2.exp_no " + " where 1 = 1 ";
		if (jobId != null && !jobId.equals("")) {
			ProcessedSql += " and t.job_id =@jobId";
			parms.add(new GlobalParameter("jobId", jobId));
		}
		if (station_id != null && !station_id.equals("")) {
			ProcessedSql += " and t.station_id =@station_id";
			parms.add(new GlobalParameter("station_id", station_id));
		}
		ProcessedSql += " order by end_time desc";
		List<RowBase> rowProcessed = DataUtil.getSelectRows(ProcessedSql, parms);
		JSONArray ProcessedData = new JSONArray();
		JSONArray PendingData = new JSONArray();
		JSONArray TimeoutHandlingData = new JSONArray();
		if (rowProcessed != null && rowProcessed.size() > 0) {
			for (int i = 0; i < rowProcessed.size(); i++) {
				HashMap<String, Object> d = rowProcessed.get(i);
				String task_status = d.get("TASK_STATUS").toString();
				Calendar deathCal = Calendar.getInstance();
				SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
				String et = d.get("END_TIME").toString();// 截止时间
				Date et_date = new Date();
				Date fishtime_date = new Date();
				Date nowdate = new Date();
				try {
					et_date = sdf.parse(et);
					deathCal.setTime(et_date);
				} catch (ParseException e) {

					e.printStackTrace();
				}
				// int timeCycleNum =
				// Integer.parseInt(d.get("TASK_TOLERANCE").toString().replaceAll("[a-zA-Z]",
				// ""));
				// if (d.get("TASK_TOLERANCE").toString().indexOf("D") > 0) {
				// deathCal.add(Calendar.DAY_OF_MONTH, timeCycleNum);
				// } else if (d.get("TASK_TOLERANCE").toString().indexOf("M") >
				// 0) {
				// deathCal.add(Calendar.MONTH, timeCycleNum);
				// }
				// Date truefishtime = deathCal.getTime();

				if (task_status.equals("0")) {// 未处理
					PendingData.add(d);
					/*
					 * if (truefishtime.getTime() >= nowdate.getTime()) {
					 * PendingData.add(d); } else { TimeoutHandlingData.add(d);
					 * }
					 */
				} else if (task_status.equals("1")) {// 已处理
					try {
						if (null != d.get("FINISH_TIME")) {
							String fishtime = d.get("FINISH_TIME").toString();// 完成时间
							fishtime_date = sdf.parse(fishtime);
							ProcessedData.add(d);
						}

					} catch (ParseException e) {

						e.printStackTrace();
					}

				}
			}
		}

		JSONObject jsobj = new JSONObject();
		jsobj.put("PendingData", PendingData);
		jsobj.put("ProcessedData", ProcessedData);
		jsobj.put("TimeoutHandlingData", TimeoutHandlingData);
		List<JSONObject> allData = new ArrayList<>();
		allData.add(jsobj);
		String result = JSONUtils.toJSONString(allData);
		return JSONUtils.toJSONString(result);
	}

	/**
	 * 获取工业污染源数据
	 * 
	 * @param userID
	 * @param groupId
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/getIndustrialPollutionGasData")
	@ResponseBody
	public String getIndustrialPollutionGasData(String userID, String groupId) throws Exception {
		checkToken(token);
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		String sql = "";
		if (groupId != null && !groupId.equals("")) {
			sql = "select sum(t.sum) as sum, t.name, t.exp_no\n" + "  from (select t1.name,t1.exp_no,(case t4.task_status when '0' then 1  else 0 end) as sum,t4.task_status from BC_SITE_INFO t1\n" + "  left join OPERATION_GROUP_STATION_ASSO t2 on t1.exp_no=t2.station_id\n" + "  left join OC_GROUP t3 on t2.operation_group_id=t3.guid\n" + "  left join OPERATION_TASK t4 on t1.exp_no=t4.station_id\n" + "  where t1.station_category='4' and t1.BUILD_STATUS='0'\n" + "  and t4.OPERATION_GROUP_ID='" + groupId + "') t   group by t.name, t.exp_no";
		} else {
			sql = "select sum(t.sum) as sum, t.name, t.exp_no\n" + "  from (select t1.name,t1.exp_no,(case t4.task_status when '0' then 1  else 0 end) as sum,t4.task_status from BC_SITE_INFO t1\n" + "  left join OPERATION_GROUP_STATION_ASSO t2 on t1.exp_no=t2.station_id\n" + "  left join OC_GROUP t3 on t2.operation_group_id=t3.guid\n" + "  left join OPERATION_TASK t4 on t1.exp_no=t4.station_id\n" + "  where t1.station_category='4' and t1.BUILD_STATUS='0'\n" + "  ) t   group by t.name, t.exp_no";
		}
		List<RowBase> rows = DataUtil.getSelectRows(sql, parms);
		if (rows != null && rows.size() >= 0) {
			return JSONUtils.toJSONString(rows);
		} else {
			return "";
		}
	}

	/**
	 * 获取工业污染源数据
	 * 
	 * @param userID
	 * @param groupId
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/getIndustrialPollutionWaterData")
	@ResponseBody
	public String getIndustrialPollutionWaterData(String userID, String groupId) throws Exception {
		checkToken(token);
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		String sql = "";
		if (groupId != null && !groupId.equals("")) {
			sql = "select sum(t.sum) as sum, t.name, t.exp_no\n" + "  from (select t1.name,t1.exp_no,(case t4.task_status when '0' then 1  else 0 end) as sum,t4.task_status from BC_SITE_INFO t1\n" + "  left join OPERATION_GROUP_STATION_ASSO t2 on t1.exp_no=t2.station_id\n" + "  left join OC_GROUP t3 on t2.operation_group_id=t3.guid\n" + "  left join OPERATION_TASK t4 on t1.exp_no=t4.station_id\n" + "  where t1.station_category='2' and t1.BUILD_STATUS='0'\n" + "  and t4.OPERATION_GROUP_ID='" + groupId + "') t   group by t.name, t.exp_no";
		} else {
			sql = "select sum(t.sum) as sum, t.name, t.exp_no\n" + "  from (select t1.name,t1.exp_no,(case t4.task_status when '0' then 1  else 0 end) as sum,t4.task_status from BC_SITE_INFO t1\n" + "  left join OPERATION_GROUP_STATION_ASSO t2 on t1.exp_no=t2.station_id\n" + "  left join OC_GROUP t3 on t2.operation_group_id=t3.guid\n" + "  left join OPERATION_TASK t4 on t1.exp_no=t4.station_id\n" + "  where t1.station_category='2' and t1.BUILD_STATUS='0'\n" + "  ) t   group by t.name, t.exp_no";
		}
		List<RowBase> rows = DataUtil.getSelectRows(sql, parms);
		if (rows != null && rows.size() >= 0) {
			return JSONUtils.toJSONString(rows);
		} else {
			return "";
		}
	}

	/**
	 * 获取污水日常巡检项
	 */
	@RequestMapping("/getWaterOperation")
	@ResponseBody
	public String getWaterOperation() throws Exception {
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		String fatherSql = "select S_DOMAINCODE \"id\",S_DOMAINCAPTION \"name\" from data_defulatdomain where S_DOMAINNAME = '运维项' and I_JB ='2' and S_DOMAINCODE like 'A1%' ORDER BY S_DOMAINCODE";
		String childSql = "select S_DOMAINCODE \"id\",S_DOMAINCAPTION \"name\" from data_defulatdomain where S_DOMAINNAME = '运维项' and I_JB ='3'";
		// 1.先搜索污水2级目录
		List<RowBase> fatherList = DataUtil.getSelectRows(fatherSql, parms);

		// 响应结果
		List<HashMap<String, Object>> resultList = new ArrayList<HashMap<String, Object>>();

		if (fatherList != null && fatherList.size() > 0) {
			List<RowBase> childList;
			String sql;
			String id;
			String name;
			HashMap<String, Object> father;
			for (RowBase bean : fatherList) {
				try {
					id = bean.get("id").toString();
					name = bean.get("name").toString();
					sql = childSql + " and S_DOMAINCODE like '" + id + "%' ORDER BY S_DOMAINCODE";
					// 2.再搜索污水3级目录
					childList = DataUtil.getSelectRows(sql, parms);
					father = new HashMap<String, Object>();
					father.put("id", id);
					father.put("name", name);
					father.put("childList", childList);
					resultList.add(father);
				} catch (Exception e) {
				}
			}
			JSONArray jsonArray = JSONArray.fromObject(resultList);
			return jsonArray.toString();
		} else {
			return new JSONArray().toString();
		}
	}

	/**
	 * 供水公司列表接口 该数据显示在第二个界面 SecondActivity
	 */
	@RequestMapping("/getSupplyWaterCompanyList")
	@ResponseBody
	public String getSupplyWaterCompanyList(String groupId) {
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		String sql = "select t1.operation_group_id as belongId, t.name STATION_NAME,t.code STATION_CODE,t2.name FACTORY_NAME,t.WWTP_ID FACTORY_CODE " + "from BC_SITE_INFO t left join (select t1.STATION_ID ,t1.OPERATION_GROUP_ID from OPERATION_GROUP_STATION_ASSO t1";
		if (groupId != null && !groupId.isEmpty()) {
			sql += " where OPERATION_GROUP_ID = '" + groupId + "'";
		}
		sql += ") t1 ON t.CODE = t1.STATION_ID left join(select EXP_NO,name from BC_ENTERPRISE_ATTR where POLL_TYPE = '3')t2 ON t2.EXP_NO = t.WWTP_ID " + "where t.STATION_CATEGORY = '3' and t1.STATION_ID IS NOT NULL AND t2.name IS NOT NULL ORDER BY t.WWTP_ID";
		List<RowBase> rowList = DataUtil.getSelectRows(sql, parms);
		if (rowList == null) {
			return "[]";
		}
		List<HashMap<String, Object>> resultList = new ArrayList<HashMap<String, Object>>();
		// 父类字段 factoryName factoryId count stationList
		// 子类字段 stationName stationId
		HashMap<String, Object> factoryMap = null;
		HashMap<String, String> stationMap = null;
		List<HashMap<String, String>> stationList = null;
		for (RowBase bean : rowList) {
			try {
				// 遍历分类
				String factroyId = bean.getValue("FACTORY_CODE").toString();
				if (factoryMap == null || !factroyId.equals(factoryMap.get("factoryId"))) {
					factoryMap = new HashMap<String, Object>();
					stationList = new ArrayList<HashMap<String, String>>();
					factoryMap.put("count", 0);
					factoryMap.put("stationList", stationList);
					factoryMap.put("factoryName", bean.getValue("FACTORY_NAME").toString());
					factoryMap.put("factoryId", factroyId);
					if (null != bean.getValue("BELONGID")) {
						factoryMap.put("belongId", bean.getValue("BELONGID").toString());
					} else {
						factoryMap.put("belongId", null);
					}
					resultList.add(factoryMap);
				}
				stationMap = new HashMap<String, String>();
				stationMap.put("stationId", bean.getValue("STATION_CODE").toString());
				stationMap.put("stationName", bean.getValue("STATION_NAME").toString());
				int count = (int) factoryMap.get("count") + 1;
				factoryMap.put("count", count);
				stationList.add(stationMap);
			} catch (Exception e) {
			}
		}
		JSONArray jsonArray = JSONArray.fromObject(resultList);
		if (jsonArray == null) {
			return "[]";
		} else {
			return jsonArray.toString();
		}
	}

	/**
	 * 供水 SecondActivity初始化所需的数据 获取组长名字 获取签名路径 获取单位列表
	 */
	@RequestMapping("/getSupplySecondInit")
	@ResponseBody
	public String getSupplySecondInit(String groupId) {
		JSONObject resultJson = new JSONObject();
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();

		// 签名照路径
		String sql = "select t.c_userealname,t.s_orgid,t.s_userid,t.sign_img from safe_user t";
		List<RowBase> rows = DataUtil.getSelectRows(sql, parms);
		if (rows != null && rows.size() > 0) {
			String result = JSONUtils.toJSONString(rows);
			resultJson.put("signPathInfo", result);
		} else {
			resultJson.put("signPathInfo", "[]");
		}

		// 获取组长的名字
		if (groupId != null && !groupId.isEmpty()) {
			sql = "select t2.c_userealname,t1.user_id from OC_GROUP_ASSO t1 left join SAFE_USER t2 on" + " t1.user_id=t2.s_userid where t1.group_head='1' ";
			sql += " and t1.group_id=@groupId";
			parms.add(new GlobalParameter("groupId", groupId));
			rows = DataUtil.getSelectRows(sql, parms);
			if (rows != null && rows.size() >= 0) {
				RowBase rowBase = rows.get(0);
				JSONObject o = new JSONObject();
				o.put("C_USEREALNAME", rowBase.getValue("C_USEREALNAME"));
				o.put("USER_ID", rowBase.getValue("USER_ID"));
				resultJson.put("leaderInfo", o);
			} else {
				resultJson.put("leaderInfo", "{}");
			}
		} else {
			resultJson.put("leaderInfo", "{}");
		}
		parms.clear();

		// 加载单位列表
		sql = "select t.S_DOMAINCODE,t.S_DOMAINCAPTION,t.s_unit from data_defulatdomain t where t.S_DOMAINNAME = 'MONITOR_PARAM'";
		rows = DataUtil.getSelectRows(sql, parms);
		if (rows != null && rows.size() >= 0) {
			resultJson.put("unitInfo", JSONUtils.toJSONString(rows));
		} else {
			resultJson.put("unitInfo", "[]");
		}

		// 返还结果
		return resultJson.toString();
	}

	/**
	 * 污水 判断是否已经签到 每次启动界面都会调用 使用频率：高
	 * 
	 * @return -1表示参数错误，0表示为签到，其它表示签到次数
	 */
	@RequestMapping("/getSewageIfSign")
	@ResponseBody
	public String getSewageIfSign(String factoryId, String userId) {
		JSONObject resultJson = new JSONObject();
		if (factoryId.isEmpty() || userId.isEmpty()) {
			resultJson.put("result", "-1");
			return resultJson.toString();
		}
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		parms.add(new GlobalParameter("factoryId", factoryId));
		parms.add(new GlobalParameter("userId", userId));
		String sql = "select  CT from OP_REGI_INFO  where " + "USER_ID = @userId " + "and WTTP_ID = @factoryId " + "AND TO_CHAR(SYSDATE,'yyyy-mm-dd') = TO_CHAR(CT,'yyyy-mm-dd')";
		List<RowBase> rows = DataUtil.getSelectRows(sql, parms);
		if (rows != null) {
			resultJson.put("result", String.valueOf(rows.size()));
		} else {
			resultJson.put("result", "0");
		}
		// 返还结果
		return resultJson.toString();
	}

	/**
	 * 供水 访问频率：高 获取报警状态，返回是报警次数
	 */
	@RequestMapping("/getSupplyWarnState")
	@ResponseBody
	public String getSupplyWarnState(String groupId) {
		JSONObject resultJson = new JSONObject();

		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		String sql = null;
		if (StringUtils.IsNullOrSpace(groupId)) {
			sql = "select t1.s_domaincaption,t2.s_domaincaption,t3.name,t3.exp_no,t.alarm_value,t.alarm_text,to_char(t.START_TIME, 'yyyy-MM-dd HH24:MI:SS') as lastupdatetime,t.CONTINUE_TIME from OP_ALAR_INFO t\n" + "left join data_defulatdomain t1 on t.type = t1.s_domaincode\n" + "left join (select * from data_defulatdomain where S_DOMAINNAME = 'MONITOR_PARAM') t2 on t.param = t2.s_domaincode\n" + "left join BC_SITE_INFO t3 on t.station_code = t3.exp_no\n" + "left join  OPERATION_GROUP_STATION_ASSO t4 on t.station_code = t4.STATION_ID\n" + "where t.is_recover = '0'   and t1.S_DOMAINNAME = '报警类型'   and t3.STATION_CATEGORY = '3'   and continue_time is not null";
		} else {
			parms.add(new GlobalParameter("groupId", groupId));
			sql = "select t1.s_domaincaption,t2.s_domaincaption,t3.name,t3.exp_no,t.alarm_value,t.alarm_text,to_char(t.START_TIME, 'yyyy-MM-dd HH24:MI:SS') as lastupdatetime,t.CONTINUE_TIME from OP_ALAR_INFO t\n" + "left join data_defulatdomain t1 on t.type = t1.s_domaincode\n" + "left join (select * from data_defulatdomain where S_DOMAINNAME = 'MONITOR_PARAM') t2 on t.param = t2.s_domaincode\n" + "left join BC_SITE_INFO t3 on t.station_code = t3.exp_no\n" + "left join  OPERATION_GROUP_STATION_ASSO t4 on t.station_code = t4.STATION_ID\n" + "where t.is_recover = '0'   and t1.S_DOMAINNAME = '报警类型'   and t3.STATION_CATEGORY = '3'   and continue_time is not null and  t4.OPERATION_GROUP_ID = @groupId";
		}
		List<RowBase> rows = DataUtil.getSelectRows(sql, parms);
		if (rows != null && rows.size() >= 0) {
			resultJson.put("warnCount", String.valueOf(rows.size()));
		} else {
			resultJson.put("warnCount", "0");
		}
		// 返还结果
		return resultJson.toString();
	}

	/**
	 * 供水 访问频率：一般 获取站点列表
	 */
	@RequestMapping("/getSupplyStation")
	@ResponseBody
	public String getSupplyStation(String groupId, String factoryId) {
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		parms.add(new GlobalParameter("groupId", groupId));
		parms.add(new GlobalParameter("factoryId", factoryId));
		// 获取报警状态 1 表示有报警
		String sql = "select t.name \"name\",t1.STATION_ID \"id\",NVL(t2.num ,0) as \"num\" from BC_SITE_INFO t " + "left JOIN(select STATION_ID,COUNT(STATION_ID) AS num from OP_TASK  where TASK_STATUS = '0' group by STATION_ID)t2 " + "on t2.STATION_ID = t.CODE " + "left join(select DISTINCT   STATION_ID from OPERATION_GROUP_STATION_ASSO where 1=1";
		if (!groupId.isEmpty()) {
			sql += "and OPERATION_GROUP_ID = @groupId ";
		}
		sql += ")t1 on t1.STATION_ID = t.CODE where WWTP_ID = @factoryId and t1.STATION_ID IS NOT NULL order by t1.station_id asc";
		List<RowBase> rows = DataUtil.getSelectRows(sql, parms);
		if (rows != null && rows.size() >= 0) {
			return JSONUtils.toJSONString(rows);
		} else {
			return "[]";
		}
	}

	/**
	 * 供水 判断是否签到（指今天） 结果0表示未签到，返回结果为签到次数
	 */
	@RequestMapping("/getSupplyIfSign")
	@ResponseBody
	public String getSupplyIfSign(String userId, String stationId) {
		JSONObject resultObject = new JSONObject();
		if (stationId == null || stationId.isEmpty() || userId == null || userId.isEmpty()) {
			resultObject.put("result", "0");
			return resultObject.toString();
		} else {
			List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
			parms.add(new GlobalParameter("userId", userId));
			parms.add(new GlobalParameter("stationId", stationId));
			String sql = "select USER_ID from OP_REGI_INFO where WTTP_ID = @stationId " + "and USER_ID = @userId and TO_CHAR(SYSDATE,'yyyy-mm-dd') = TO_CHAR(CT,'yyyy-mm-dd')";
			List<RowBase> rows = DataUtil.getSelectRows(sql, parms);
			if (rows != null && rows.size() > 0) {
				resultObject.put("result", String.valueOf(rows.size()));
			} else {
				resultObject.put("result", "0");
			}
		}
		return resultObject.toString();
	}

	/**
	 * 供水 收集站点坐标 结果 0表示失败，1表示成功
	 */
	@RequestMapping("/collectSupplyWaterMapInfo")
	@ResponseBody
	public String collectSupplyWaterMapInfo(String row) {
		JSONObject resultObject = new JSONObject();
		if (row == null || row.isEmpty()) {
			resultObject.put("result", "0");
			return resultObject.toString();
		}
		JSONObject rowJson = JSONUtils.toJSONObject(row);
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		parms.add(new GlobalParameter("stationId", rowJson.getString("stationId")));
		parms.add(new GlobalParameter("stationName", rowJson.getString("stationName")));
		parms.add(new GlobalParameter("x", rowJson.getString("x")));
		parms.add(new GlobalParameter("y", rowJson.getString("y")));
		parms.add(new GlobalParameter("dateTime", rowJson.getString("dateTime")));
		parms.add(new GlobalParameter("userId", rowJson.getString("userId")));
		parms.add(new GlobalParameter("groupId", rowJson.getString("groupId")));
		parms.add(new GlobalParameter("address", rowJson.getString("address")));
		String sql = "INSERT INTO SUPPLY_SIGN_IN (GUID,STATION_ID,STATION_NAME,X,Y,USER_ID,GROUP_ID,SIGNIN_TIME,ADDRESS)" + " SELECT NVL(MAX(ROWNUM),0), @stationId , @stationName , @x , @y , @userId , @groupId , @dateTime , @address " + "FROM SUPPLY_SIGN_IN";
		int i = DataUtil.ExecuteUpdateSql(sql, parms);
		if (i == 0) {
			resultObject.put("result", "1");
		} else {
			resultObject.put("result", "0");
		}
		return resultObject.toString();
	}

	/**
	 * 根据地表水站点获取在线设备
	 * 
	 * @param flow_type
	 * @param wwtp_id
	 * @return
	 */
	@RequestMapping("/getSurfaceEquipmentByStation")
	@ResponseBody
	public String getSurfaceEquipmentByStation(String stationId) {
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		String sql = "select t.name as paraname,t1.S_DOMAINCAPTION,t2.name,t2.device_typenum,t2.device_num,t1.s_unit from BC_SITE_POLL t " + "left join data_defulatdomain t1 on t.name = t1.S_DOMAINCODE  " + "left join BC_SITE_DEVICE_RPT  t2 on t.device_id = t2.guid " + "where t1.S_DOMAINNAME='MONITOR_PARAM' ";
		if (stationId != null && !stationId.equals("")) {
			sql += " and t.site_id =@wwtp_id";
			parms.add(new GlobalParameter("wwtp_id", stationId));
		}
		List<RowBase> rows = DataUtil.getSelectRows(sql, parms);
		if (rows != null && rows.size() >= 0) {
			return JSONUtils.toJSONString(rows);
		} else {
			return "";
		}
	}

	/**
	 * 供水 判断是否签到 signCount 获取站点坐标 x,y
	 * 
	 * @return signCount:-1 表示不需要签到 0表示未签到
	 */
	@RequestMapping("/getSupplyWaterInitTask")
	@ResponseBody
	public String getSupplyWaterInitTask(String stationId, String groupId) {
		JSONObject resultObject = new JSONObject();
		resultObject.put("signCount", "0");
		resultObject.put("x", "0");
		resultObject.put("y", "0");
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		parms.add(new GlobalParameter("stationId", stationId));
		parms.add(new GlobalParameter("groupId", groupId));
		if (!stationId.isEmpty()) {
			String signSql = "select X,Y from SUPPLY_SIGN_IN WHERE STATION_ID = @stationId ";
			List<RowBase> rows = DataUtil.getSelectRows(signSql, parms);
			if (rows != null && rows.size() >= 0) {
				RowBase rowBase = rows.get(0);
				if (rowBase != null) {
					resultObject.put("x", rowBase.getValue("X"));
					resultObject.put("y", rowBase.getValue("Y"));
				}
			}
			if (!groupId.isEmpty()) {
				String coordSql = "select SIGNIN_TIME from OP_SUPPLY_SIGN_IN where STATION_ID = @stationId and GROUP_ID = @groupId and TO_CHAR(to_date(SIGNIN_TIME,'yyyy-mm-dd hh24:mi:ss'),'yyyy-mm-dd')=TO_CHAR(SYSDATE,'yyyy-mm-dd')";
				rows = DataUtil.getSelectRows(coordSql, parms);
				if (rows != null && rows.size() >= 0) {
					resultObject.put("signCount", String.valueOf(rows.size()));
				}
			} else {
				resultObject.put("signCount", "1");
			}
		}
		return resultObject.toString();
	}

	/**
	 * 供水 签到
	 * 
	 * @return 0:签到失败 1:签到成功
	 */
	@RequestMapping("/getSupplyWaterSignInResult")
	@ResponseBody
	public String getSupplyWaterSignInResult(String row) {
		JSONObject resultObject = new JSONObject();
		resultObject.put("result", "0");
		if (row == null || row.isEmpty()) {
			return resultObject.toString();
		}
		JSONObject rowJson = JSONUtils.toJSONObject(row);
		try {
			String signInRange = PropertiesUnit.getValue("distance");
			String distanceStr = rowJson.getString("distance");
			double distance = Double.parseDouble(distanceStr);
			double distanceNormal = Double.parseDouble(signInRange);
			// 距离太远不能签到
			if (distance > distanceNormal) {
				return resultObject.toString();
			}
		} catch (Exception e) {
		}
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		parms.add(new GlobalParameter("stationId", rowJson.getString("stationId")));
		// parms.add(new GlobalParameter("stationName",
		// rowJson.getString("stationName")));
		parms.add(new GlobalParameter("x", rowJson.getString("x")));
		parms.add(new GlobalParameter("y", rowJson.getString("y")));
		parms.add(new GlobalParameter("dateTime", rowJson.getString("dateTime")));
		parms.add(new GlobalParameter("userId", rowJson.getString("userId")));
		parms.add(new GlobalParameter("groupId", rowJson.getString("groupId")));
		parms.add(new GlobalParameter("address", rowJson.getString("address")));
		String sql = "INSERT INTO OP_SUPPLY_SIGN_IN" + " (GUID,STATION_ID,X,Y,USER_ID,GROUP_ID,SIGNIN_TIME,ADDRESS)" + " VALUES (SYS_GUID(),@stationId,@x,@y,@userId,@groupId,@dateTime,@address)";
		int i = DataUtil.ExecuteUpdateSql(sql, parms);
		if (i == 0) {
			resultObject.put("result", "1");
		} else {
			resultObject.put("result", "0");
		}
		return resultObject.toString();
	}

}
